使用 pipenv 创建 virtualenv 时设置 python 版本 [英] Set python version when creating virtualenv using pipenv
问题描述
使用使用 Debian 4.14.34-v7+ 的 Raspberry Pi,我试图将 pipenv
设置为 Python 3.6.5 作为 Python 的默认版本.我首先通过在 Pi 上编译来安装 Python 3.6(数小时......).创建robot"目录后,我使用 sudo pip3 install pipenv
和 pipenv install --three
安装 pipenv
.
Using a Raspberry Pi using Debian 4.14.34-v7+, I am trying to get pipenv
set up with Python 3.6.5 as the default version of Python. I first install Python 3.6 by compiling it on the Pi (hours...). After making a 'robot' directory, I then install pipenv
with sudo pip3 install pipenv
and pipenv install --three
.
然后我启动shell并打开Python,得到Python 3.5.3…
Then I start the shell and open up Python, getting Python 3.5.3…
pi@raspberrypi:~/robot $ pipenv shell
Spawning environment shell (/bin/bash). Use 'exit' to leave.
. /home/pi/.local/share/virtualenvs/robot-XZ3Md9g0/bin/activate
pi@raspberrypi:~/robot $ . /home/pi/.local/share/virtualenvs/robot-XZ3Md9g0/bin/activate
(robot-XZ3Md9g0) pi@raspberrypi:~/robot $ python
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170124] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
然后我通过 pipenv --python 3.6
更改 virtualenv,但是在它正确(显然)安装后,我立即收到警告,pipenv 仍然需要 Python 3.5…
I then change the virtualenv by pipenv --python 3.6
, but after it correctly (apparently) installs, I immediately get the warning that pipenv still expects Python 3.5…
(robot-XZ3Md9g0) pi@raspberrypi:~/robot $ pipenv --python 3.6
Virtualenv already exists!
Remove existing virtualenv? [Y/n]: y
Removing existing virtualenv…
Creating a virtualenv for this project…
Using /usr/local/bin/python3.6m (3.6.5) to create virtualenv…
⠋Running virtualenv with interpreter /usr/local/bin/python3.6m
Using base prefix '/usr/local'
New python executable in /home/pi/.local/share/virtualenvs/robot-XZ3Md9g0/bin/python3.6m
Also creating executable in /home/pi/.local/share/virtualenvs/robot-XZ3Md9g0/bin/python
Installing setuptools, pip, wheel...done.
Virtualenv location: /home/pi/.local/share/virtualenvs/robot-XZ3Md9g0
Warning: Your Pipfile requires python_version 3.5, but you are using 3.6.5 (/home/pi/.local/share/v/r/bin/python).
$ pipenv check will surely fail.
(robot-XZ3Md9g0) pi@raspberrypi:~/robot $ python
Python 3.6.5 (default, May 3 2018, 11:25:17)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
当我第一次创建 virtualenv 时,如何设置 pipenv
以查找 Python 3.6?我可以手动进入并编辑 Pipfile,但这似乎违背了让 pipenv
为我处理事情的目的.
How do I set up pipenv
to look for Python 3.6, when I first create the virtualenv? I can manually go in and edit the Pipfile, but that seems to be defeating the purpose of having pipenv
take care of things for me.
推荐答案
如果您想更改现有环境的 Python 版本,编辑 Pipfile"是正确的方法.
"Edit the Pipfile" is the right way to go if you want to change the Python version of an existing environment.
如果您想使用 Python 3.6 创建一个新环境,您可以运行
If you want to create a new environment using Python 3.6, you can run
pipenv install --python 3.6
而不是
pipenv install --three
这应该可以解决问题.
如果您创建新环境,请务必删除旧的 Pipfile(s),否则命令将失败.
Just be certain to delete the old Pipfile(s) if you create the new environment or else the commands will fail.
这篇关于使用 pipenv 创建 virtualenv 时设置 python 版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!