Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

People also ask

How do I specify Python in Pipenv?

And, if you want to use that local Python version, you can indicate that to Pipenv by executing: pipenv install --python 3.8. There you can see that after the pipenv shell command has been executed, the name of the virtual environment appeared between brackets at the beginning of the line.

Can I have both Python 2 and 3?

So to be able to use multiple versions of Python: install Python 2. x (x is any version you need) install Python 3.


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?