简体   繁体   English

Virtualenv - Python 3 - Ubuntu 14.04 64位

[英]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虚拟环境:

  1. 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

  2. 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.

相关问题 如何使用Anaconda Python 3.6在Ubuntu 14.04 64bit中安装pygame - How to install pygame in Ubuntu 14.04 64bit with Anaconda Python 3.6 一个32位的Python脚本调用64位virtualenv中运行的多处理 - a Python script in 32 bit invoking multiprocessing running in 64 bit virtualenv 已创建的virtualenv在ubuntu 14.04中不起作用 - Already created virtualenv is not working in ubuntu 14.04 如何使用python 2.7 64位在virtualenv中安装pywin32? - How to install pywin32 in virtualenv with python 2.7 64 bit? ubuntu 14.04,eclipse Neon,python 2.7,Django 1.9,Pydev和virtualenv的配置不会创建src文件夹 - Config for ubuntu 14.04, eclipse Neon, python 2.7, Django 1.9, Pydev and virtualenv doesn't create src folder 在Ubuntu 14.04(64bit)上安装TensorFlow-0.9.0rc0不受此平台支持 - Install TensorFlow-0.9.0rc0 on Ubuntu 14.04 (64bit) gets not a supported wheel on this platform Windows(64位)上的Python 2.7.8(64位)是Ubuntu(64位)上的2.7.8(64位)的一半 - Python 2.7.8 (64bit) on Windows (64bit) is half as fast as 2.7.8 (64bit) on Ubuntu (64bit) python ubuntu virtualenv - &gt;错误 - python ubuntu virtualenv -> error 如何在64位机器上使用32位Python中的virtualenv? - How to use virtualenv in 32-bit Python on a 64-bit machine? 在OSX上为virtualenv设置Python 32位和64位模式 - Setting Python 32-bit and 64-bit mode for virtualenv on OSX
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM