Is the current working directory no longer inherited from the calling process from python 2.5?

I upgraded my python version on a Windows 2003 server from 2.4 to 2.5.

In 2.4, I can import the file "sub1.py" from the subdirectory c: \ application \ subdir \ as follows:

import sub1

while the calling script main.py, which lives in c: \ application, runs as follows:

c:\application\subdir>python ..\main.py

But in 2.5 it no longer works for me:

C:\application\subdir>python ..\main.py
Traceback (most recent call last):
  File "main.py", line 3, in <module>
    import sub1
ImportError: No module named sub1

Now I can put an empty file

__init__.py

in subdir and import like this:

import subdir.sub1 as sub1

Was there a change in python 2.5? This would mean that the current working directory in python 2.4 was inherited from the calling process, and in python 2.5 it is installed where the main script lives.

[Edit3] . , , , . [/Edit3]

+3
5

:

  • subdir , __init__.py
  • : from subdir import sub1
+1

sub.py :

import sub      # not sub1
+4

, python . sys.path.

script ( ), :

import sys

for x in sys.path:
  print x

python , , script.

, PYTHONPATH, ". \".

+2

I guess it sub1's a typo? In your question, you sometimes refer to sub, sometimes to sub1.

I will first verify that the sub.py file exists in c:\application.

  • Check the permissions of the sub.py file and application directory. Can the user read the sub.py file? Can python interpreter create * .pyc file?
  • Also, manually delete the sub.pyc file, in case there is a problem with the old version of pyc.
+1
source

add this directory to your python path

0
source

Source: https://habr.com/ru/post/1706712/


All Articles