1

So, I have Anaconda, OSGeo and Python2.7 installed on my computer.

I'm also using Spyder. In Spyder :

>>> import sys
>>> sys.executable
'C:\\ProgramData\\Anaconda3\\pythonw.exe'

Which is what I want.

However, in the windows command line and powershell :

$ python3
>>> import sys
>>> sys.executable
'C:\\Progra~1\\OSGeo4W\\bin\\python3.exe'

Which is not what I want. I want to use 'C:\\ProgramData\\Anaconda3\\pythonw.exe' (or python.exe, not sure) when using python3 in the command line.

Also :

$ pip3
Fatal error in launcher: Unable to create process using '"'

I don't get why python3 in the windows command line points to OSGeo's version of Python3. Here is my path :

C:\Python27\;C:\Python27\Scripts;C:\ProgramData\Anaconda3;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Git\cmd;C:\Program Files\PuTTY\;C:\Progra~1\OSGeo4W\bin\;C:\Program Files\Microsoft\R Open\R-3.4.0\bin

I also have an environment variable called PYTHONHOME

C:\ProgramData\Anaconda3

Moreover (for completeness of information), I have python 2 installed :

$ python
  File "C:\ProgramData\Anaconda3\lib\site.py", line 177
    file=sys.stderr)
        ^
SyntaxError: invalid syntax

($ pip outputs the same thing).

Having python3 and python2.7 both work when using python3 and python (respectively) in the windows command line would be a nice bonus, but it's not really my priority.

1
  • Most distributions of Windows Python, including the official PSF distribution, do not include a "python3.exe" file. pip happens to install with "pip3" and "pip3.6", etc, because it's following a Unix convention. Windows Python in general does not follow that convention. At least one of the core developers for Windows Python vocally protests including "pythonX.exe" and "pythonX.Y.exe" files, and everyone else, as far as I can tell, pretty much doesn't care, so it's skewed against it. Commented Aug 9, 2017 at 13:43

1 Answer 1

1

There are probably several things you have to take care of:

In general the search order of the Windows PATH is from left to right starting with the system PATH. The first matching element wins. In your case this is correct because the system will search C:\ProgramData\Anaconda3\ first. However in that folder is no executable called python3 by default. On my system I created a simlink pointing to python.exe. On your system you can do it in PowerShell like this:

New-Item -Path C:\ProgramData\Anaconda3\python3.exe -ItemType SymbolicLink -Value C:\ProgramData\Anaconda3\python.exe

pip is located in Scripts\ folder so in your case you have to add C:\ProgramData\Anaconda3\Scripts to your PATH and create the corresponding simlinks again. In this case you have to create two of them because pip.exe is appending its name to the script that is trying to call (i.e. if your exe file is called foo.exe it will try to call foo-script.exe which does not exist) you can create the simlinks in PowerShell with those two commands:

New-Item -Path C:\ProgramData\Anaconda3\Scripts\pip3.exe -ItemType SymbolicLink -Value C:\ProgramData\Anaconda3\Scripts\pip.exe

and

New-Item -Path C:\ProgramData\Anaconda3\Scripts\pip3-script.py -ItemType SymbolicLink -Value C:\ProgramData\Anaconda3\Scripts\pip-script.py

Like this you will be able to use python3 and pip3 from your cmd line. Please check for similar problems with your python2 installation folder.

Hope it helps.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.