Learn Python: pipenv

Hello,
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'

Pipfile:

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

[packages]
numpy = "*"

[dev-packages]

[requires]
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

2 Likes

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

2 Likes

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

1 Like

Hi Toastedpitabread,

I am having a similar issue and was wondering if you might have some other advise. I can use pip install numpy and it works just fine, but when I switch to pipenv install numpy I am getting the Error text: Could not fetch URL https://pypi.org/simple/numpy/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/numpy/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

I have installed pip env

[[source]]

url = "https://pypi.org/simple"

verify_ssl = true

name = "pypi"

[packages]

[dev-packages]

[requires]

python_version = "3.8"

and i did try the trick to activate it, but that didn’t fix it.

I am using windows virtual studio and have downloaded and installed new versions of Anaconda, Visual Studio, Python, and Numpy.

Attached is a screenshot.

Thanks!

Hm, I feel like @tgrtim may know better than me!

1 Like

Hmm not really I’m afraid :expressionless:, I’ve seen other users encounter this error (where installation with pip worked but pipenv didn’t) but I’m entirely sure why, something funny with the virtualenv perhaps. As for why there are far too many possibilities to guess at a solution (multiple installs and path issues, name collisions with .dll files and a few others).

@dataninjaog there are several suggested possible fixes at the following link (not all are windows based) but I’m afraid this might be one you have to hunt down yourself because I have no idea how to replicate it-

2 Likes

Hi, Thank you both for the attempt.

Adding what my solution was for others future reference. I’ll preface with this is what worked for me, and your mileage may vary. I don’t think this solution has one answer, but I could be wrong. After a lot of reading it lead me to update to the latest Python and downloaded Open SSL for WIN 64 EXE and install, I did it from this site: Shining Light Productions - Home. There were other options but I chose this as the best option, in the future I’ll look to take notes on the “debugging” process if that’s what this was.

Cheers!