Python 3-如何告诉Pipenv使用python 3而不是python 2?

Bre*_*old 5 python python-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.
Run Code Online (Sandbox Code Playgroud)

这是我运行脚本时的样子:

[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'
Run Code Online (Sandbox Code Playgroud)

如您所见,问题是当我安装它时,它使用的是python 2而不是python 3 (Using /usr/bin/python2 (2.7.14))

如何告诉Pipenv使用Python 3而不是Python 2?

还是有安装请求的特定python 3方法?

Gio*_*ous 7

您可以将以下几行添加到pip文件中:

[requires]
python_version = "3.6"
Run Code Online (Sandbox Code Playgroud)

或运行(假设您已经在计算机上安装了Python 3.6):

pipenv --python 3.6
Run Code Online (Sandbox Code Playgroud)


小智 7

创建环境时,Pipenv 会自动扫描您的系统以查找与给定版本匹配的 Python。

pipenv --python VERSION
Run Code Online (Sandbox Code Playgroud)