简体   繁体   中英

installing python 3 and python2.7 on windows

I use python2.7 mostly, but I wanted to use python3.3 for a specific task. I referred to the existing questions Python 3x and python 2.x The solution suggested there did not work for me. I have couple of questions based on the issues I have been facing.

  1. Adding python3.3 to the path variable.Some post( add python27_path ) suggested to copy the file and rename it. I tried renaming C:\\Python3.3\\python.exe to C:\\Python3.3\\python3.exe. But this did not work for me.

  2. Adding libraries to PYTHONPATH: Had added C:\\Python33\\Lib\\site-packages to the PYTHONPATH. When I ran the code with Python3.3, it was using libraries of python2.7. Is it possible for the libraries to coexist on the same machine and if I call python2.7 it should look only for its modules?

Those lovely people over at python have come up with the perfect solution for you as a part of python 3.3 - a launcher for windows that works all this out for you take a look about half way down this page.

The other option is to have a switcher script which changes your path and pythonpath variables for you.

Well, you can explicitly specify which version of python to use by making sure that you add the appropriate python location to the beginning of the path before you invoke the python command. Something like this.

Let's assume that you PATH variable in Windows is : c:\\windows\\system32;c:\\python27\\;...

Execute your python scripts using 3.3 this way :

SET PATH = "c:\python33\";%PATH%
python yourscript.py

Execute your python scripts using 2.7 this way :

SET PATH = "c:\python27\";%PATH%
python yourscript.py

This is a good way to execute scripts without having to install too many third party software products. A simple BAT file can then solve your requirement.

The variant

 SET PATH = "c:\python27\";%PATH%

is invalid. You should use

 SET PATH=C:\python33\;%PATH%

On windows, if you already added both versions of python to the PATH, you can use:

py -2.7

or

py -3.6

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