pypa / pipenv

Python Development Workflow for Humans.
https://pipenv.pypa.io
MIT License
24.81k stars 1.86k forks source link

Can pipenv find Pythons on Windows? #580

Closed jacebrowning closed 6 years ago

jacebrowning commented 6 years ago

Using 7.2.1 and this Pipfile:

[[source]]

url = "https://pypi.python.org/simple"
verify_ssl = true

[requires]

python_version = "3.6"

[packages]

testpackage = "*"

Installation with a full Python path works:

$ pipenv install --python=C:\\Python36\\python.exe
Creating a virtualenv for this project…
Using C:\Python36\python.exe to create virtualenv…
Running virtualenv with interpreter C:\Python36\python.exe
Using base prefix 'C:\\Python36'
New python executable in C:\projects\template-python-demo\.venv\Scripts\python.exe
Installing setuptools, pip, wheel...done.

But pipenv is unable to locate Python otherwise despite it being installed in the normal location (on AppVeyor):

$ pipenv install
Warning: Python 3.6 was not found on your system…
You can specify specific versions of Python with:
  $ pipenv --python path\to\python

Is pipenv able to locate Pythons on Windows? Having this feature work would mean that build scripts no longer need to workaround the Windows case and can get rid of hardcoded paths. 🎉

kennethreitz commented 6 years ago

We have tests for it, so yes. They need to be in your PATH though.

techalchemy commented 6 years ago

@jacebrowning isn't this the same behavior as you would expect on linux if python wasn't on your path?

jacebrowning commented 6 years ago

@techalchemy Not really, because Pythons on Windows all have the same filename -- it's not a simple matter of looking for python3.6 on the path. If both C:\Python27 and C:\Python36 are on the PATH, does pipenv simply check the --version of each one?

kennethreitz commented 6 years ago

it does.

kennethreitz commented 6 years ago

but, for version 3.6, it checks for python.exe, python3.exe, python36.exe and python3.6.exe.

kennethreitz commented 6 years ago

and runs all of those, if they are found by where, with --version to see what version they are.

uranusjr commented 6 years ago

Just want to put it out there, an alternative method is checking for registry entries, outlined in PEP 514. This works for all “standard” Python distributions; I’m not sure about PyPy and Anaconda etc.

This is what the py.exe launcher on Windows does to detect what Python version to choose when you invoke py -3, py -3.5 etc., without requiring any python.exe to be added to PATH.

kennethreitz commented 6 years ago

i think our current method is working well, and is cross-platform.

kennethreitz commented 6 years ago

does python3 not ship a python3.exe on windows?

jacebrowning commented 6 years ago

@kennethreitz No, that doesn't appear to be the case in these AppVeyor logs:

set PATH=C:\Python%PYTHON_MAJOR%%PYTHON_MINOR%;%PATH%
set PATH=C:\Python%PYTHON_MAJOR%%PYTHON_MINOR%\Scripts;%PATH%
pip install pipenv==7.1.1
$ python --version
Python 3.6.1

$ python2 --version
sh: command not found: python2

$ python3 --version
sh: command not found: python3

$ pipenv --version
pipenv, version 7.1.1
pipenv install --dev
Warning: Python 3.6 was not found on your system� 
You can specify specific versions of Python with:
  $ pipenv --python path\to\python
kennethreitz commented 6 years ago

try where python.exe

kennethreitz commented 6 years ago

p.s. this is working fine for us with pipenv using --python python

jacebrowning commented 6 years ago

@kennethreitz Here's the additional debugging information you requested (from this build log):

$ where python.exe
C:\Python36\python.exe
C:\Python27\python.exe

$ set
ALLUSERSPROFILE='C:\ProgramData'
APPDATA='C:\Users\appveyor\AppData\Roaming'
APPVEYOR=True
...
OS=Windows_NT
OSTYPE=msys
PATH='/c/Python36/Scripts:/c/Python36:/c/Perl/site/bin:/c/Perl/bin:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Program Files/7-Zip:/c/Program Files/Microsoft/Web Platform Installer:/c/Tools/GitVersion:/c/Tools/PsTools:/c/Program Files/Git LFS:/c/Program Files (x86)/Subversion/bin:/c/Program Files/Microsoft SQL Server/120/Tools/Binn:/c/Program Files/Microsoft SQL Server/Client SDK/ODBC/110/Tools/Binn:/c/Program Files (x86)/Microsoft SQL Server/120/Tools/Binn:/c/Program Files/Microsoft SQL Server/120/DTS/Binn:/c/Program Files (x86)/Microsoft SQL Server/120/Tools/Binn/ManagementStudio:/c/Tools/WebDriver:/c/Program Files (x86)/Microsoft SDKs/TypeScript/1.4:/c/Program Files (x86)/Microsoft Visual Studio 12.0/Common7/IDE/PrivateAssemblies:/c/Program Files (x86)/Microsoft SDKs/Azure/CLI/wbin:/c/Ruby193/bin:/c/Tools/NUnit/bin:/c/Tools/xUnit:/c/Tools/MSpec:/c/Tools/Coverity/bin:/c/Program Files (x86)/CMake/bin:/c/go/bin:/c/Program Files/Java/jdk1.8.0/bin:/c/Python27:/c/Program Files/nodejs:/c/Program Files (x86)/iojs:/c/Program Files/iojs:/c/Users/appveyor/AppData/Roaming/npm:/c/Program Files/Microsoft SQL Server/130/Tools/Binn:/c/Program Files (x86)/MSBuild/14.0/Bin:/c/Tools/NuGet:/c/Program Files (x86)/Microsoft Visual Studio 14.0/Common7/IDE/CommonExtensions/Microsoft/TestWindow:/c/Program Files/Microsoft DNX/Dnvm:/c/Program Files/Microsoft SQL Server/Client SDK/ODBC/130/Tools/Binn:/c/Program Files (x86)/Microsoft SQL Server/130/Tools/Binn:/c/Program Files (x86)/Microsoft SQL Server/130/DTS/Binn:/c/Program Files/Microsoft SQL Server/130/DTS/Binn:/c/Program Files (x86)/Microsoft SQL Server/110/DTS/Binn:/c/Program Files (x86)/Microsoft SQL Server/120/DTS/Binn:/c/Program Files (x86)/Apache/Maven/bin:/c/Python27/Scripts:/c/Tools/NUnit3:/c/Program Files/Mercurial:/c/Program Files/LLVM/bin:/c/Program Files/dotnet:/c/Program Files/erl8.3/bin:/c/Tools/curl/bin:/c/Program Files/Amazon/AWSCLI:/c/Program Files (x86)/Microsoft SQL Server/140/DTS/Binn:/c/Program Files (x86)/Microsoft Visual Studio 14.0/Common7/IDE/Extensions/Microsoft/SQLDB/DAC/140:/c/Program Files (x86)/Yarn/bin:/cmd:/usr/bin:/c/ProgramData/chocolatey/bin:/c/Tools/vcpkg:/c/Program Files (x86)/nodejs:/c/Program Files/Microsoft Service Fabric/bin/Fabric/Fabric.Code:/c/Program Files/Microsoft SDKs/Service Fabric/Tools/ServiceFabricLocalClusterManager:/c/Users/appveyor/AppData/Local/Yarn/bin:/c/Users/appveyor/AppData/Roaming/npm:/c/Program Files/AppVeyor/BuildAgent:/c/MinGW/bin'
PATHEXT='.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.CPL'
PIPENV_IGNORE_VIRTUALENVS=true
PIPENV_NOSPIN=true
PIPENV_SHELL_COMPAT=true
PIPENV_VENV_IN_PROJECT=true
...
PWD=/c/projects/template-python-jm6i8/TemplateDemo
PYTHON_MAJOR=3
PYTHON_MINOR=6
ProgramData='C:\ProgramData'
ProgramW6432='C:\Program Files'
SESSIONNAME=Console
SHELL=/usr/bin/bash
...

$ pipenv install --dev
Warning: Python 3.6 was not found on your system� 
You can specify specific versions of Python with:
  $ pipenv --python path\to\python
kennethreitz commented 6 years ago

I didn't know where could return multiple lines! We might have to update our code to reflect that.

kennethreitz commented 6 years ago

Okay, put the code in place to detect multiple pythons of the same name. ✨🍰✨

kennethreitz commented 6 years ago

this vastly improves our support for non-windows systems too!

kennethreitz commented 6 years ago

7.2.8 released, which should fix this!

kennethreitz commented 6 years ago

confirmed!

kennethreitz commented 6 years ago

thanks for the great feature!

jacebrowning commented 6 years ago

I can confirm that pipenv==7.2.8 is finding Python correctly. Thanks!

OmarGonD commented 6 years ago

Same problem with version pipenv==8.2.6 & Windows 10.

By default Python 3.6.3 installs to: C:\Program Files\Python36 and pipenv cannot read it. Says cannot find python.exe in directory: C:\Program (when specifiying directory as the author of the issue mentioned).

So I thought it could be that blank spaces is causing problems for pipenv. I've uninstalled Python36 and installed it again in: C:\Python36 and no more problems.

Thank you for your library.

kennethreitz commented 6 years ago

make sure you're using the latest version!

mrh1997 commented 6 years ago

The Windows Installer provides an option to Add python to the PATH which is off by default (at least on the two PCs I tested):

screenshot

Even worse python 2.7 does not add itself to the PATH at all (at least on my PCs).

Thus I think the method is not really reliable on Windows.

Searching via PEP-514 as proposed earlier is the only reliable way on windows systems.

uranusjr commented 6 years ago

@mrh1997 I’ve started working on this in #1259. Not reflected in the title but it includes a PEP-514-baed Python finder. I haven’t had time recently to polish it, but many I can rebase and try to fix some tests today. Also if there’s any feedback it would be awesome!

mrh1997 commented 6 years ago

@uranusjr No Problem. Let me know if you finished. I will test it on my machines then...

dmwyatt commented 6 years ago

I don't usually do python on Windows, so maybe this is a stupid question, but can't pipenv use the python launcher for windows if its available to find the correct python location? This is available to be installed in the python installer, and is probably what most windows users should be using anyway.

https://docs.python.org/3/using/windows.html#launcher

On my Windows system without python on my PATH, the launcher finds the correct python interpreter.

uranusjr commented 6 years ago

@dmwyatt The Python launcher also uses PEP-514 to discover Python versions. Reading the registry directly saves a subprocess call.