Why is PYTHONPATH ignored?

I install PYTHONPATH in a directory containing several .py files.

When I switch to python and click "import file", the file cannot be found (it says "There is no module named wsj10").

If, however, I connect to the directory and repeat the same process, then the file will be found.

I just don't know why PYTHONPATH is ignored. I followed the exact instructions from the instructions for installing any software, so I know that I am doing the right thing.

Any circumstances under which PYTHONPATH will be ignored or the import will not work?

Thanks.

Following the comment below, you will find the transcript here:

  • untar file1.tgz to file1 /. The file1.tgz file contains a library / file called file1.py.

  • enter into the shell:

    export PYTHONPATH=`pwd`/file1/:./ 
  • echo $PYTHONPATH indicates that a variable has been set.

  • run python and type "import file1"

I get an error message:

 Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named file1 

If I do "cd file1" first and then import file1, it identifies the file.

+1
source share
1 answer

Any circumstances under which PYTHONPATH will be ignored or the import will not work?

Yes. I installed PYTHONPATH in my /home/me/.bashrc and everything worked fine from the terminal, but when Apache w / mod_wsgi runs my python scripts, it acts under sysem or a dedicated user who knows nothing about my .bashrc.

In this particular situation, I just used the apache configuration to set the python path for apache (WSGIPythonPath option).

+1
source

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


All Articles