[英]Virtualenv - Python 3 - Ubuntu 14.04 64 bit
I am trying to install virtualenv for Python 3 on Ubuntu 64bit 14.04. 我想在Ubuntu 64bit 14.04上为Python 3安装virtualenv。
I have installed pip for Python3 using: 我使用以下方法为Python3安装了pip:
pip3 install virtualenv
and everything works fine. 一切正常。 Now though I am trying to use virtualenv command to actually create the environment and getting the error that it is not install (i guess because I haven't installed it for Python 2 and that is what it is trying to use)
现在虽然我正在尝试使用virtualenv命令来实际创建环境并获得它不安装的错误(我想因为我没有为Python 2安装它而且它正在尝试使用它)
How do I use the virtualenv for Python 3? 我如何使用virtualenv for Python 3? I have searched the documentation but can't see where it says what to do.
我搜索了文档,但看不出它在哪里做。
I had the same issue coming from development environments on OS X where I could create Python 3 virtual environments by simply invoking virtualenv
and the path to the target directory. 我从OS X上的开发环境中遇到了同样的问题,我可以通过简单地调用
virtualenv
和目标目录的路径来创建Python 3虚拟环境。 You should be able to create a Python 3.x virtual environment in one of two ways: 您应该能够以两种方式之一创建Python 3.x虚拟环境:
Install virtualenv
from the PyPi as you've done ( $ pip3 install virtualenv
), then by calling it as a module from the command line: 安装
virtualenv
从PyPI中为你做( $ pip3 install virtualenv
),然后通过调用它的命令行的模块:
$ python3 -m virtualenv /path/to/directory
Use the venv module, which you can install through apt-get
. 使用venv模块,您可以通过
apt-get
安装。 (Note that Python 3.3 is when this module was introduced, so this answer assumes you're working with at least that): (请注意,Python 3.3是在引入此模块时,所以这个答案假定您至少使用了这个模块):
$ sudo apt-get install python3.4-venv
Then you can set up your virtual environment with 然后,您可以使用设置虚拟环境
$ pyvenv-3.4 /path/to/directory
and activate the environment with 并用。激活环境
$ source /path/to/directory/bin/activate
You might also look at this post , which discusses differences between the venv
module and virtualenv
. 您还可以查看这篇文章 ,其中讨论了
venv
模块和virtualenv
之间的venv
。 Best of luck! 祝你好运!
除了所有答案之外,您还可以使用以下命令。
virtualenv venv --python=python3.5
您也可以使用此命令:
virtualenv -p python3 envname
The venv
became standard library from python3 v3.3 . venv
成为python3 v3.3的标准库 。 So if you get more recent python3 version, this can always done by: 因此,如果您获得更新的python3版本,这可以通过以下方式完成:
python3 -m venv <path-or-name-of-virtualenv>
# choose correct python3, which is the name of your python3 cmd
No need to install or download anything before hand, when succeeded, pip3 will come with the virtualenv just created. 无需事先安装或下载任何东西,当成功时,pip3将随刚创建的virtualenv一起提供。 By this way, on most Linux, it will print out message to tell you what to do, for example it need
python3.4-venv
. 通过这种方式,在大多数Linux上,它会打印出消息告诉你该做什么,例如它需要
python3.4-venv
。
To active the virtualenv 积极的virtualenv
source <path-to-the-virtualenv>/bin/activate
# then to deactive it:
deactivate
Just as a point of clarification if you are on ubuntu 14.04.1, the python3.4-venv
package is not available (though it is in 14.04.5) 如果您使用的是ubuntu 14.04.1,那么
python3.4-venv
软件包是不可用的(虽然它是在14.04.5)
You can get around this by installing the python-virtualenv
package and creating virtualenvs via one of the methods described in the other answers: 您可以通过安装
python-virtualenv
包并通过其他答案中描述的方法之一创建virtualenvs来解决这个问题:
virtualenv -p python3 envname
or 要么
virtualenv envname --python=python3.x
Just follow below commands: 只需按照以下命令:
step-1 pip3 install virtualenv (if using python3) step-1 pip3 install virtualenv(如果使用python3)
step-2 mkdir ~/my_environment (dir where you want to create your vir-env) step-2 mkdir~ / my_environment(dir你要创建你的vir-env)
step-3 python3 -m virtualenv ~/my_environment step-3 python3 -m virtualenv~ / my_environment
step-4 source ~/my_environment/bin/activate step-4 source~ / my_environment / bin / activate
Done!! 完成!
I would rather suggest to create an alias for activating this vir-env on bashrc 我宁愿建议在bashrc上创建一个用于激活这个vir-env的别名
step-1 vim ~/.bashrc step-1 vim~ / .bashrc
step-2 alias myenv='source ~/my_environment/bin/activate' #add this line at the bottom step-2 alias myenv ='source~ / my_environment / bin / activate'#add这一行在底部
step-3 :wq #save the file using 步骤3:wq #save文件使用
step-4 source ~/.bashrc step-4 source~ / .bashrc
step-5 myenv #check your shortcut(alias) step-5 myenv #check你的快捷方式(别名)
Voyla Done!! Voyla完成!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.