在特定目录中创建Python虚拟环境 [英] Create Python Virtual Environment in a Specific Directory

查看:76
本文介绍了在特定目录中创建Python虚拟环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Anaconda,并且一直在设置虚拟环境,因为我需要运行的脚本是用Python 2和Python 3编写的.我希望能够激活我的Python 3虚拟环境在特定目录中-即Python 3将仅在该目录中运行,而所有其他目录将保留在我在Anaconda中设置的默认Python 2中.我的问题是,每次尝试激活新环境时,它都会更改机器上各处使用的python版本,而不是仅在我想要的一个目录中使用.是否可以创建仅限于特定位置的虚拟环境?

I have Anaconda and I've been playing around with setting up virtual environments since I have scripts that I need to run that have been written in Python 2 and Python 3. I want to be able to activate my Python 3 virtual environment in a specific directory - ie Python 3 will only run in that directory and all other directories will remain at the default Python 2 that I have set in Anaconda. My problem is that every time I try to activate a new environment, it changes the version of python used everywhere on my machine instead of just in the one directory that I want. Is it possible to create a virtual environment that is limited to a specific location?

我尝试了以下操作:

conda create --prefix=testEV1 python=3.5
source activate testEV1

这会将我在工作区中所有地方的python版本更改为3.5.

and this changes my version of python everywhere in my workspace to 3.5.

推荐答案

否.您一次只能执行一个默认的Python安装.

No. You only have a single default Python installation in effect at any one time.

使用完一个virtualenv后,您可以使用 deactivate 来返回"标准的物理默认Python安装.

Once you're done using one virtualenv you can use deactivate to go "back" to the standard, physical default Python installation.

或者您可以将不同的命令会话与在每个会话中激活的不同虚拟环境一起使用.

Or you can use different command sessions with different virtual environments activated in each session.

或者您可以每次从命令行显式调用一个版本的Python,而不仅仅是使用当前默认的活动版本.

Or you can explicitly invoke one version or another of Python from the command line each time, rather than just using the currently active-by-default one.

这篇关于在特定目录中创建Python虚拟环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆