简体   繁体   English

为python 2.7创建虚拟环境

[英]create virtual environment for python 2.7

I want to install django, but my system which it's os is mac has python 2.6 which can't support django. 我想安装django,但是我的操作系统是mac的python 2.6无法支持django。 so I installed python 2.7 but at that time when I typed python in terminal it response the version is 2.6 after searching I change it to python 2.7 where both of them are still on my computer, when I want to install django it still install it for 2.6 so I decide to install virtual environment but when I create a new environment using "virtualenv venv" it produce environment with python version 2.6! 所以我安装了python 2.7,但是那时我在终端中键入python时,搜索后响应的版本是2.6,将其更改为python 2.7,而这两个都仍在我的计算机上,当我想安装django时,它仍会安装2.6,所以我决定安装虚拟环境,但是当我使用“ virtualenv venv”创建新环境时,它将使用python版本2.6产生环境! I really confused what should I do to create virtual environment with python 2.7? 我真的很困惑如何使用python 2.7创建虚拟环境?

The short answer is that you can edit the PATH in ~/.bash_profile to make sure that path for python 2.7 is in front of 2.6 version. 简短的答案是,您可以在〜/ .bash_profile中编辑PATH,以确保python 2.7的路径在2.6版本之前。

It is a good/common practice to not touch the system python on MAC OS and install a latest version using homebrew. 在Mac OS上不触摸系统python并使用自制软件安装最新版本是一种好/常见的做法。 After you installed brew you can install python by: 安装brew之后,您可以通过以下方式安装python:

brew install python

Homebrew will take care of the PATH. 自制程序将处理PATH。 After that you will be able to install packages and control virtual environments with your 2.7 installation. 之后,您将能够使用2.7安装来安装软件包并控制虚拟环境。

You can specify your python interpreter as a prefix to virtualenv_install 您可以将python解释器指定为virtualenv_install的前缀

Refer to this post: Is it possible to install another version of Python to Virtualenv? 请参阅此文章: 是否可以在Virtualenv中安装另一个版本的Python?

What I mean to say is create a new virtual env with the correct python interpreter by specifying it as such: 我的意思是通过这样指定正确的python解释器来创建一个新的虚拟环境:

mkdir virtualenvs
cd virtualenvs
~/.localpython/bin/virtualenv py2.7 --python=/home/<user>/.localpython/bin/python2.7

(See the stackoverflow post I mentioned) (请参阅我提到的stackoverflow帖子)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM