Title: Script’s directory not in sys.path with embeddable Windows distribution
Type: behavior Stage:
Components: Versions:
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: skoslowski, ssapin
Priority: normal Keywords:

Created on 2018-09-29 07:49 by ssapin, last changed 2019-02-27 08:27 by skoslowski.

Messages (3)
msg326671 - (view) Author: Simon Sapin (ssapin) Date: 2018-09-29 07:49 documents:

> As initialized upon program startup, the first item of this list, path[0], is the directory containing the script that was used to invoke the Python interpreter.

On Windows with an embeddable zip file distribution, this does not happen.

Steps to reproduce:

* Create a file that contains `import bar`
* Create an empty file
* With your usual Python installed from the "normal" executable installer, check that `python` runs without output or error
* Download and extract
* Run `..\python-3.7.0-embed-amd64\python`

Expected result:

The script runs again without output or error.

Actual result:

Traceback (most recent call last):
  File "", line 1, in <module>
    import bar
ModuleNotFoundError: No module named 'bar'

This might be an occurrence of, since the embeddable distribution has a python37._pth file that contains "" and "."

print(sys.path) shows [

This StackOverflow question describes the same issue:
msg326678 - (view) Author: Simon Sapin (ssapin) Date: 2018-09-29 14:00
Removing python37._pth restores the documented behavior, I don’t know if it has adverse effects.
msg336736 - (view) Author: Sebastian Koslowski (skoslowski) * Date: 2019-02-27 08:27
I ran into the same problem.

Seems like adding an empty sys.path entry through the _pth file is not supported at the moment:

For now, I have enabled 'import site' and edited that (inside the zip file) to include 'sys.path.insert(0, "")'
Date User Action Args
2019-02-27 08:27:51skoslowskisetnosy: + skoslowski
messages: + msg336736
2018-09-29 14:00:50ssapinsetmessages: + msg326678
2018-09-29 07:49:04ssapincreate