我正在尝试使用requests模块,这是我安装它的方式:
[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.
这是我运行脚本时的样子:
[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'
问题在于我安装时使用的是Python 2而不是 Python 3,你可以看到这个信息:(Using /usr/bin/python2 (2.7.14))
如何告诉pipenv使用Python 3而不是Python 2?
或者是否有一种特定的Python 3方式来安装requests库?
pipenv --python 3.5
命令,如需更多帮助,请输入pipenv --help
。 - Lokesh Sanapallipipenv --three
。 - VPfB