简体   繁体   English

用特定的python版本制作virtualenv(MACOS)

[英]make virtualenv with specific python version(MACOS)

I installed brew, python3 (default and latest version) and pip3, pyenv. 我安装了brew,python3(默认和最新版本)和pip3,pyenv。

TensorFlow does not support python3.7 now, so I heard that I should make a virtualenv that runs 3.6 or lower version independently. TensorFlow现在不支持python3.7,所以听说我应该制作一个独立运行3.6或更低版本的virtualenv。

I installed python 3.6.7 by pyenv install 3.6.7 but can't make virtualenv -p 3.6.7 (mydir) because 3.6.7 is not in the PATH ( usr/local/bin ). 我通过pyenv install 3.6.7安装了python 3.6.7,但由于3.6.7不在PATHusr/local/bin )中,所以无法使virtualenv -p 3.6.7 (mydir) )。

How can I update my PATH ? 如何更新我的PATH

You don't need the executable to be on the PATH. 您不需要将可执行文件放在PATH上。 Assuming you want /usr/local/bin/python3.6.7 to be used in the virtual environment, 假设您要在虚拟环境中使用/usr/local/bin/python3.6.7

virtualenv -p /usr/local/bin/python3.6.7 mydir

Updating your PATH is easy: 更新您的PATH很容易:

PATH=/usr/local/bin:$PATH

This will only update it in your current session; 这只会在您当前的会话中进行更新; you might want to add this to your shell's startup files to make it permanent. 您可能需要将此添加到Shell的启动文件中以使其永久。 This is a common FAQ but depends on a number of factors (your shell, etc) so google for details. 这是一个常见的常见问题解答,但取决于许多因素(您的外壳等),因此请使用google了解详细信息。 Here is one question with several popular variants in the answers: Setting PATH environment variable in OSX permanently 这是一个在回答中带有几个流行变体的问题: 在OSX中永久设置PATH环境变量

I know that this doesn't answer the question exactly, but for completeness I'd like to add an Anaconda solution. 我知道这并不能完全回答问题,但是为了完整起见,我想添加一个Anaconda解决方案。 Provided that an Anaconda environment is present on the system, a new Python environment can be created using conda create -n py36 python=3.6 pip . 假设系统上存在Anaconda环境,则可以使用conda create -n py36 python=3.6 pip一个新的Python环境。 The name py36 can be arbitrarily chosen (could also be eg myenv or tensorflow ), the desired Python version (in this example 3.6) is specified by python=3.6 . 可以任意选择名称py36 (也可以是例如myenvtensorflow ),所需的Python版本(在此示例中为3.6)由python=3.6指定。

This environment can then be activated using conda activate py36 (or whatever name you assigned in the previous step). 然后可以使用conda activate py36 (或您在上一步中指定的任何名称)激活此环境。 Once the environment is active, you can install tensorflow via pip : pip install tensorflow-gpu . 一旦环境处于激活状态,您可以安装tensorflow通过pippip install tensorflow-gpu To deactivate the current environment and return to the default environment, use conda deactivate . 要停用当前环境并返回默认环境,请使用conda deactivate In this way, you don't have to modify PATH variables. 这样,您无需修改PATH变量。

See also this documentation page for more details on the Anaconda environment. 另请参阅此文档页面以获取有关Anaconda环境的更多详细信息。

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

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