Brent Heigold
Brent Heigold

Reputation: 1273

Python 3 - How do you tell pipenv to use python 3 and not python 2?

I am trying to use the requests module, here is how I installed it:

[ec2-user@ip-xxx-xx-xx-xxx newslookup]$ pipenv install requests
Creating a virtualenv for this project...
Pipfile: /var/www/html/newslookup/Pipfile
Using /usr/bin/python2 (2.7.14) to create virtualenv...
ā ‡ Creating virtual environment...Already using interpreter /usr/bin/python2
  No LICENSE.txt / LICENSE found in source
New python executable in /home/ec2-user/.local/share/virtualenvs/newslookup-5acwuw4D/bin/python2
Also creating executable in /home/ec2-user/.local/share/virtualenvs/newslookup-5acwuw4D/bin/python
Installing setuptools, pip, wheel...
done.

āœ” Successfully created virtual environment!
Virtualenv location: /home/ec2-user/.local/share/virtualenvs/newslookup-5acwuw4D
Creating a Pipfile for this project...
Installing requests...
Adding requests to Pipfile's [packages]...
āœ” Installation Succeeded
Pipfile.lock not found, creating...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
āœ” Success!
Updated Pipfile.lock (ab273c)!
Installing dependencies from Pipfile.lock (ab273c)...
  šŸ   ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ā–‰ 5/5 ā€” 00:00:01
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.

Here is what it looks like when I run my script:

[ec2-user@ip-xxx-xx-xx-xxx newslookup]$ python3 nasdaq_scrape_sec.py
Traceback (most recent call last):
  File "nasdaq_scrape_sec.py", line 5, in <module>
    import requests
ModuleNotFoundError: No module named 'requests'

As you can see, the problem is that when I install it, it is using python 2 instead of python 3 (Using /usr/bin/python2 (2.7.14))

How can I tell pipenv to use Python 3 instead of Python 2?

Or is there a specific python 3 way of installing requests?

Upvotes: 16

Views: 30345

Answers (3)

Giorgos Myrianthous
Giorgos Myrianthous

Reputation: 39930

The easiest way is to run (assuming you want 3.6):

pipenv --python 3.6

Alternatively and as a more persistent solution, you can add the following lines into the pip file:

[requires]
python_version = "3.6"

Upvotes: 25

sahasrara62
sahasrara62

Reputation: 11247

just call the pipenv from python3, it will do the job

 python3 -m pipenv install requests

Upvotes: 4

user10298794
user10298794

Reputation:

While creating a environment ,Pipenv will automatically scan your system for a Python that matches that given VERSION.

pipenv --python VERSION

Upvotes: 7

Related Questions