Learn Python: pipenv

Watching Learn Python 3, pipenv video (https://www.codecademy.com/courses/learn-python-3/videos/learn-python3-pipenv) and stuck at creating virtual env. I installed the latest Python version, in CMD I installed pipenv using pip. After that I installed VS Code with Python extension. First I created a new folder. In this folder, I created venv and installed numpy module. Then I type pipenv shell and python3. When I try to import numpy, it gives and error:

>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'


url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

numpy = "*"


python_version = "3.9"

Please, help. I was googling it for almost 2 hours, reinstalled python an pip and it’s not helping.

Did you activate the venv you installed numpy in?

Something like

$ source venv/bin/activate
#in the directory of target venv

To activate it said to run

pipenv shell

Ah yes, sorry, I’m thinking of regular venv.

The question stands though, did you activate it in the same directory before running the file?

Here’s a screenshot of my steps

Screen Shot 2021-02-09 at 3.12.07 PM

Check your spelling of pipenv

I fixed it below in the code

I think this is what’s happening: You need to activate your environment before the install. Otherwise it’s installing outside the environment. (I don’t use pipenv, I use venv. So the details might be off on this, but it’s vaguely the same gist)

Order of operations:

  • create a new virtual environmnet $ pipenv --python 3.7
  • activate it $ pipenv shell
  • install numpy $ pipenv install numpy
  • run python to test and import numpy
$ python
>>> import numpy

You can also type pipenv -h for help

1 Like

OMG, at last, it’s working. Thanks a lot for your help!


Great! Virtual environments were one of the hardest things when I started out with python.

1 Like