通过MAC控制台上的Python 2.7.15,virtualenv使用不同版本的Python创建环境 [英] With Python 2.7.15 on a MAC console, virtualenv creates an environment with a different version of Python

查看:185
本文介绍了通过MAC控制台上的Python 2.7.15,virtualenv使用不同版本的Python创建环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在Mac上的控制台的摘录,您可以看到控制台上的Python是2.7.15,但在环境上它变成了2.7.10,这是一个较旧的版本...有关为什么和方式的任何帮助修复它将是最受欢迎的!

Here is an extract of my console in a Mac, as you can see the Python on the console is 2.7.15 but on the environment it becomes 2.7.10 which is an older version... any help on why and how to fix it would be most welcomed!

dhcp-18-57:Wakeup6 **jbs$ python**  
**Python 2.7.15** (default, May  1 2018, 16:44:14)  
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin  
Type "help", "copyright", "credits" or "license" for more information.  
>>> exit()  

dhcp-18-57:Wakeup6 jbs$ virtualenv env  
New python executable in /Users/jbs/PycharmProjects/Wakeup6/env/bin/python  
Installing setuptools, pip, wheel...done.  

dhcp-18-57:Wakeup6 jbs$ source env/bin/activate  

(env) dhcp-18-57:Wakeup6 **jbs$ python**  
**Python 2.7.10** (default, Oct 23 2015, 19:19:21)  
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin  
Type "help", "copyright", "credits" or "license" for more information.  
>>> exit()

推荐答案

谢谢大家的投入.我终于想出了解决方法.困难的部分是找出如何定位python 2.7.15的安装位置,因为我是在其他地方通过反复试验发现它的,所以我将在响应中保持原样.我还没有找到可以提供完整路径的命令(也许专家可以告诉我们如何从简单的python到完整路径).

Thank you all for your input. I finally figured out how to solve it. The difficult part was finding out how to locate the place where python 2.7.15 was installed which I'll leave intact in the response since I found it by trial and error looking in other places. I have not found a command that gives you the full path (perhaps an expert can tell us how to go from the laconic which python to the full path).

我发现有趣的是,调用virtualenv时控制台使用什么并不重要.重要的是用于安装virtualenv的Python版本,这是将要使用的默认版本.

What I find interesting is that it does not really matter what the console uses when calling virtualenv. What matters is the version of Python used to install virtualenv which is the default version that will be used.

基本上,必须在virtualenv中使用-p选项,并确保找到所需版本的python的正确位置.

Essentially one has to use the -p option in virtualenv and make sure to find the right location where the desired version of python is.

dhcp-18--41:WakeUp8 jbs$ virtualenv -p /usr/local/Cellar/python@2/2.7.15/bin/python env
Running virtualenv with interpreter /usr/local/Cellar/python@2/2.7.15/bin/python
New python executable in /Users/jbs/PycharmProjects/WakeUp8/env/bin/python2.7
Also creating executable in /Users/jbs/PycharmProjects/WakeUp8/env/bin/python
Installing setuptools, pip, wheel...done.
dhcp-18-189-34-41:WakeUp8 jbs$ python
Python 2.7.15 (default, May  1 2018, 16:44:14) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

dhcp-18--41:WakeUp8 jbs$ pwd
/Users/jbs/PycharmProjects/WakeUp8

dhcp-18-189-34-41:WakeUp8 jbs$ source env/bin/activate

(env) dhcp-18-189-34-41:WakeUp8 jbs$ python
Python 2.7.15 (default, May  1 2018, 16:44:14) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

这篇关于通过MAC控制台上的Python 2.7.15,virtualenv使用不同版本的Python创建环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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