4

I have several people on my team that are running into an intermittent problem running some very basic Python commands. The following is all in Windows 10, using the Python Launcher (the py command that allows you to setup a default Python – in our case Python 3.7).

Running from a Git repo root directory pip can fail.

$ py -m pip install --upgrade pip
C:\Apps\Python37\python.exe: can't open file '<unprintable file name>': [Errno 2] No such file or directory

or setting up a virtual environment.

$ py –m venv .venv
C:\Apps\Python37\python.exe: can't open file '<unprintable file name>': [Errno 2] No such file or directory

Clearly it is finding and running Python, but then Python is unable to open some file in the middle of the process. It can't even name the file/directory. I did some searching and the '<unprintable file name>' part may be due to spaces in a folder, but that's the best I've got.

Notes and things we have tried:

  • A few people in the team have never seen this, with the same tools installed (VS Code as IDE, etc.)
  • It is a mix of Python 3.7.5 and 3.7.6, I think all 64-bit (Note, I original had 3.7.4 with the same setup and have never seen this)
  • Moving Python out of the "C:\Program Files" and the user directory doesn't seem to help
  • It is definitely intermittent for all the people that ran into it, sometimes running a few other commands will work, then the bad one suddenly works as well
  • We generally use Git Bash as the terminal
  • Exactly how Python37 and Python37/Scripts shows up in the path varies (whether at beginning/end and User or System path).

I can't find any pattern. We did remove old Python folders from the path, removed all Python paths from the User Path, and moved the current Python 3.7 folders to the top of the system path for one person and it may have fixed the problem.

Question:

Any idea what this is? How do you even dig further into this to figure out what is failing?

Update

This may only be a problem until pip is updated (either in the system install location and/or in any new virtual environment created). It might be going away after success is intermittently achieved.

I never personally had this issue on my PC with 3.7.4, nor by updating to 3.7.6 in-place as a test, it may be a defect related to version 3.7.5 or 3.7.6 along with the specific version of pip that comes with those packages. However, once pip is successfully updated to 19.3.1, it seems to go away.

My current guesses:

  • It has something to do with specific versions of Python 3.7 (3.7.5 or 3.7.6) and Pip 19.x interacting with each other poorly, missing a dependency, or something similar.
  • It is related to spotty internet or proxy connections to the internet that are causing partial downloads and pip is not detecting the issue (our proxy can take a while to establish the initial connection with some SSO and security stuff going on in the background).
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
LightCC
  • 9,804
  • 5
  • 52
  • 92
  • Does the output literally say ``? – ChrisGPT was on strike Jan 16 '20 at 22:32
  • @Chris Yes. If you search on that, you can find a handful of people posting the same output `''` with both the angle brackets and the single quotes. – LightCC Jan 16 '20 at 22:44
  • What happens when you manually go into the scripts folder/python37 folder and click on python.exe? Does the executable launch? Is it there? And did you guys use a docker to set up the environment or was it all manual/preinstalled by someone else? First guess is that you are missing key files which would indicate someone set people up incorrectly. – Edeki Okoh Jan 16 '20 at 23:05
  • @EdekiOkoh The setup is very basic - install Python from a windows install executable from Python.org. We've played with different locations (my install is in `C:\apps\python37`and I haven't had any problems). And the issue is - this is **definitely intermittent**. It's bizarre. Regarding python itself, it is running. We can always `py --version` and get the correct response, or `py -0p` and it prints out the expected installed Python versions and locations, with the 3.7 one set as default (we using `PY_PYTHON 3.7` env variable to set that). – LightCC Jan 16 '20 at 23:27
  • @LightCC Do the different users happen to have different system locales set? In any case, which locale(s) is(are) set? – a_guest Jan 20 '20 at 21:12
  • @a_guest These are all US/English. **Note:** added an update that it may be okay after it succeeds for the first time (possibly tied to pip updating successfully?) – LightCC Jan 20 '20 at 22:17
  • Assuming one of my users still has the issue next time we meet, or if a new user to our group runs into this, I will try to debug per [this question and answer](https://stackoverflow.com/q/59829515/6501141) on the python/pip/venv source code. – LightCC Jan 20 '20 at 22:19
  • 1
    On Unix you could run your command through `strace` and check which file system calls it issues (in order to find out what that unprintable file name is). There seem to be [equivalent alternatives for Windows](https://stackoverflow.com/q/3847745/3767239), so maybe one of them helps to shed some light on the issue. – a_guest Jan 20 '20 at 23:01
  • @LightCC I just `grep`'ed the CPython source code for ["unprintable file name"](https://github.com/python/cpython/blob/47be7d0108b4021ede111dbd15a095c725be46b7/Modules/main.c#L319) and it seems to occur when the filename cannot be encoded according to the various settings [detailed here](https://github.com/python/cpython/blob/47be7d0108b4021ede111dbd15a095c725be46b7/Python/fileutils.c#L725). So maybe you could check what settings your users have. [PEP 529](https://www.python.org/dev/peps/pep-0529/) and [PEP 540](https://www.python.org/dev/peps/pep-0540/) might be relevant/helpful as well. – a_guest Jan 21 '20 at 21:13
  • Also do you know whether the error correlates with running the commands from Git Bash vs. Terminal / Powershell? – a_guest Jan 21 '20 at 21:17
  • Does the problem only occur when running pip or venv, or when you run *any* Python script or start an interactive Python session (i.e., simply run `$ py`). – mkrieger1 Jan 22 '20 at 12:50
  • **Update:** This issue appears to only occur when first setting things up for my users, then it seems to go away after something gets setup or succeeds for the first time... so I haven't had a chance to debug. **Also,** I ran into a weird file permission issue with the Git GUI my team uses (Git Extensions) that only happens when Python is accessing files in the repo and the GUI has the current commit selected. This might be related. – LightCC Feb 12 '20 at 18:41

0 Answers0