How do I setup virtualenvwrapper for Windows PowerShell? - python

I have this installed
on Windows 7
Python 2.7.6 (my default, with virtualenv installed)
Python 2.4.4
Python 2.5.4
Python 2.6.6
Python 3.3.3
virtualenv 1.10.1
virtualenvwrapper_powershell-12.7.8-py2.7
I want to test code on all of those python installations.
(Related question about missing support for Python 2.4./2.5:
How do I setup virtualenv environments for Python 2.4 and 2.5 versions on Windows? )
This is what I tried so far:
Trying virtualenv directly:
Python 2.6 works as expected:
C:\Users\martin\.virtualenvs>virtualenv -p c:\apps\Python26\python.exe env26
Running virtualenv with interpreter c:\apps\Python26\python.exe
New python executable in env26\Scripts\python.exe
Installing Setuptools..............done.
Installing Pip.............done.
C:\Users\martin\.virtualenvs>env26\Scripts\activate
(env26) C:\Users\martin\.virtualenvs>python
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
Python 2.7 and 3.3 also work as expected.
Trying virtualenvwrapper:
Python 2.6, 2.7, and 3.3 work as expected:
C:\Users\martin\.virtualenvs>mkvirtualenv -p c:\apps\Python26\python.exe env26_w
Running virtualenv with interpreter c:\apps\Python26\python.exe
New python executable in env26_w\Scripts\python.exe
Installing Setuptools.........done.
Installing Pip................done.
(env26_w) C:\Users\martin\.virtualenvs>python
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
Trying virtualenvwrapper on Powershell:
Creating and activating Python 2.6 does not give an error, but starts Python27
when activated:
PS C:\Users\martin> mkvirtualenv -p C:\apps\Python26\python.exe env_26_ps
New python executable in env_26_ps\Scripts\python.exe
Installing Setuptools........done.
Installing Pip.......................done.
Added activation script por Powershell to C:\Users\martin\.virtualenvs/env_26_ps\Scripts.
(env_26_ps)PS C:\Users\martin> python
Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
The env_26_ps\Scripts folder contains files like pip-2.7.exe and python.exe (2.7).
Similar behavior for Python 3.3

Related

Move from python 2 to python 3 on Mac

I have both python 2.7.16 and python 3.7.3 on my Macbook air.
I don't use python 2.7.16 so I want to remove it, but I understood that this could break my Mac.
I am frustrated from using python3 and pip3 instead of python and pip is there a way to make all of the python3 commands to be accessed by using python (without 3) instead of python 2 and make python 2 be accessible by using python2?
tnx ahead
(base) shrub$ /usr/bin/py
pydoc python python2.7 pythonw
pydoc2.7 python-config python2.7-config pythonw2.7
Looking in /usr/bin there is a python executable (which when run opens a shell with python3) and a python2.7 executable (which when run opens a shell with python2).
(base) shrub$ python
Python 3.7.4 (default, Aug 13 2019, 15:17:50)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
(base) shrub$ python2.7
Python 2.7.10 (default, Feb 22 2019, 21:55:15)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Running python scripts with python (python hello.py for example) should default to python3 and running scripts with python2.7 (python2.7 hello.py for example) will run them with python2.
Also there is a script called 2to3 which can help you with converting your python2 code to python3 :)
https://docs.python.org/3.0/library/2to3.html

Running specific python interpreters form command line

When I open CMD (on windows 10) and enter python it initializes python 3.6.0
C:\>python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
Now I recently also installed 2.7.6 the interpreter. How can I call both version of Python from CMD?
desired outcome
C:\>python
Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> ^Z
C:\>python2.6
Python 2.7.6 (default, Nov 10 2013, 19:24:24) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
You can use Python launcher for Windows:
Python 2.7 interptreter:
C:\> py -2.7
Python 3.6 interpreter:
C:\> py -3.6
You also can run a script with a specific interpreter:
C:\> py -2.7 myScript.py
If its windows machine, to open a specific version of python you can use py from the command line.
example:
py2.7 #for version 2.7
and
py3.6 #for version 3.6
if its a Linux machine you can use the following commands in the command line python
python2.7 #opens version 2.7
and
python3.6 #opens version 3.6

TensorFlow on Windows 10: “not a supported wheel on this platform” error

I was following the guide steps until get the "not a supported wheel on this platform" error. I checked the Anaconda is properly installed with the following version information:
Python 3.6.0 |Anaconda 4.3.0 (64-bit)| (default, Dec 23 2016, 11:57:13) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anyone know how to solve this?
I think it's only available for Python 3.5.x not 3.6.
You can quickly create a 3.5 environment with conda create -n tensorflow python=3.5

Python 2.7 Anaconda2 installed in windows

My Python 2 environmental path:
C:\Python27
C:\Python27\Scripts
My Python 3 environmental path:
C:\Python35
C:\Python35\Scripts
I set the environmental path for Anaconda2
C:\Users\User\Anaconda2\Scripts
C:\Users\User\Anaconda2
But when i typed python to enter the shell in cmd (C:\Users\user)
Importing the module of Anaconda like numpy or matplotlib
C:\Users\User>python
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named numpy
C:\Users\User>cd Anaconda2
C:\Users\User\Anaconda2>python
Python 2.7.12 |Anaconda 4.1.1 (64-bit)| (default, Jun 29 2016, 11:07:13) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import numpy
>>>
So i don't know
1.Why my module can't import while not in Anaconda2
2.It is said that the path of Python2 will overrdie the Python,so how to enter in the Python35 shell?
thanks everybody
Each Python installation has its own libraries. As you will see, you are not running the same Python 2.7 interpreter when you run with Anaconda active as you are without (I assume that's either the system Python or one you installed yourself).
Libraries installed in one interpreter aren't available to others. You should consider learning about conda environments to allow you to manage multiple projects easily.
The command deactivate should terminate the Anaconda environment, and if the Python 3 interpreter is first on your PATH you should then be able to run it. Another way would be to explicitly use the command
C:\Python35\python
which should work even with Anaconda active.
Caution: it's a long time since I used Windows, and I don't have current information on getting multiple Pythons to live happily together on Windows.

Python gives "SyntaxError: invalid syntax" under Cygwin but not in CMD, after hitting "return"?

I have used Cygwin for years and recently started using Python. I decided not to use the Cygwin provided Python (for various other issues) and installed a native Windows version. However, when running this version in the Cygwin shell it behaves a bit different than when running on the Windows Command line (CMD). The problem is that hitting "return" when in Cygwin, results in a "SyntaxError", whereas doing the same in CMD, does not. Here's what happens:
In Cygwin:
$ python
Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
File "<stdin>", line 1
^
SyntaxError: invalid syntax
>>> ^Z
In (Win) CMD:
Microsoft Windows [Version 6.0.6002]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.
C:\Windows\System32>python
Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> ^Z
I cannot comprehend what's going on. Any ideas?
PS. I've had python on my machine many times before (including the Cygwin native version), without any problem, but have since removed all those. I've also looked at this post, suggesting that it could have something to do with the character set or end-of-line character...
Ha! I just found an old latent environment variable: PYTHONUNBUFFERED=1 and disabled it, as suggested elsewhere. Now it works. Apparently this is a known Python bug... Another way is to run your python interpreter with: python -E, which disables all python related environment variables.

Categories