简体   繁体   中英

i have both python2 and 3, I want to use python2 but on powershell I'm using python3

我正在做一个学习python的简易教程,他们使用的是python2.7,我下载了它,但无法从3.3切换回2.7。我操作PATH变量,添加了C:\\ Python27,但这没有任何其他建议吗?

Rename the python interpreter executables to their respective versions. The OS is just executing the first 'python' executable it finds in the path, which is probably the 3.x version. So in command line, you can type python2 or python3 to select the version of interpreter you want.

Another option is.

you can create virtual environment for python 2.7 version. And Activate the environment. And use your virtual env for your python 2.7 learning.

username@mypc:~/dev/learn-code$ virtualenv myenv -p /usr/bin/python
Already using interpreter /usr/bin/python
New python executable in /home/username/dev/learn-code/myenv/bin/python
Installing setuptools, pip, wheel...done.
username@mypc:~/dev/learn-code$ 
username@mypc:~/dev/learn-code$ 
username@mypc:~/dev/learn-code$ source myenv/bin/activate
(myenv) username@mypc:~/dev/learn-code$ 
(myenv) username@mypc:~/dev/learn-code$ python
Python 2.7.6 (default, Oct 26 2016, 20:30:19) 
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print "hello"
hello
>>> 
  • Setting up in windows environment also similar. see this link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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