Python path control when moving code from a development computer

I have a python project with this directory structure and these files:

/home/project_root
|---__init__.py
|---setup
       |---__init__.py
       |---configs.py
|---test_code
       |---__init__.py
       |---tester.py

The tester script imports from setup / configs.py the link "setup.configs". It works fine on my development machine.

This works on a development computer (Linux). When I transfer this to another (Linux) computer, I install PYTHONPATH with

PYTHONPATH = "/home/project_root"

But when I run tester.py, it cannot find the configs module. And when I run the interactive Python interpreter, sys.path does not include the / home / project _root directory. But / home / project_root appears when I repeat $ PYTHPATH.

What am I doing wrong here?

( .bashrc, PYTHONPATH - Django www-. , apache Django PYTHONPATH, , , .)

. - , . - sudo ( Ubuntu ) , . - script sudo, www-data (b/c , apache Django). - , script ( ).

. .

+3
3

script import setup.configs

import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.path.pardir))

sys.path - , python python. , , , . , . : sys doc.

: .pth /usr/local/lib/python2.X/site-packages/..pth - , python. :

/home/project_root
+4

python . , - "../" . :

sys.path.append("../")
0

( .bashrc, PYTHONPATH - Django www-. , apache Django PYTHONPATH, , , .)

Django, , Django? Django :

  • Django manage.py Python . sys.path, DJANGO_SETTINGS_MODULE.
  • Django libraries include extensive unit testing capabilities, and you can easily extend this functionality with your own testing tools. Running tests in a Django project is as simple as running a single command through manage.py.
0
source

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


All Articles