PYTHONPATH ignored

前端 未结 7 1674
离开以前
离开以前 2021-01-04 10:33

Environment: debian 4.0

Python 2.4

My \'project\' is installed in:

/usr/lib/python2.4/site-packages/project.

Bu

相关标签:
7条回答
  • 2021-01-04 10:50

    I don't believe you have any control over where the PYTHONPATH gets inserted into the actual path list. But that's not the only way to modify the path - you can update sys.path yourself, before you try to import the project.

    Edit: In your specific case, you can modify the path with

    import sys
    sys.path.insert(2, '/home/me/dev/project/src')
    
    0 讨论(0)
  • 2021-01-04 11:01

    Not a direct answer to you question, but you could also use a virtualenv to create a development environment. In that virtualenv you can then install your product in /home/me/dev/project/src as a development package: "python setup.py develop".

    This way you don't have to change your PYTHONPATH manually. Just activate the virtualenv if you want to use the development code.

    0 讨论(0)
  • 2021-01-04 11:02

    I found the problem (I've missed early on when somebody pointed me to Where is Python's sys.path initialized from?).

    It seems that easy_install creates a pth file /usr/lib/python2.4/site-packages/easy-install.pth which is then loaded by site.py. This inserts the site-packages path in the sys path before the PYTHONPATH. Not nice.

    0 讨论(0)
  • 2021-01-04 11:03

    I think you set up PYTHONPATH to /home/me/build/project/src since /home/me/dev/project/src does not appear in sys.path, but /home/me/build/project/src does.

    0 讨论(0)
  • 2021-01-04 11:06

    I see '/usr/lib/python2.4/site-packages' in your path prior to '/home/me/dev/project/src', does that matter? What happens when you switch the two?

    From the docs:

    When PYTHONPATH is not set, or when the file is not found there, the search continues in an installation-dependent default path

    So perhaps you didn't find your working copy on your PYTHONPATH as you had thought?

    0 讨论(0)
  • 2021-01-04 11:12

    It sounds like the src directory doesn't have an __init__.py file. It's not a proper package.

    0 讨论(0)
提交回复
热议问题