我正在尝试使用请求模块,这是我安装它的方式:
[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 安装请求的方式?
原文由 Brent Heigold 发布,翻译遵循 CC BY-SA 4.0 许可协议
最简单的方法是运行(假设你想要
3.6
):或者,作为一种更持久的解决方案,您可以将以下行添加到 pip 文件中: