I've looked through the setup.py documentation and am still having some difficulties with what I feel should be pretty basic.
I've broken this down to a simple example project that I'm trying to get running, my project's directory layout is as follows:
myproject
setup.py
src\
main.py
extern\
__init__.py
mytest.py
myproject/setup.py:
#!/usr/bin/env python
from distutils.core import setup
setup(name = "myproject",
package_dir = {'':"src"},
packages = ["extern"],
scripts = ["src/main.py"],
)
myproject/src/main.py:
#! /usr/bin/env python
import extern.mytest as mytest
mytest.print_test()
myproject/src/extern/mytest.py:
#!/usr/bin/env python
def print_test():
print "YAY"
myproject/src/extern/_init_.py is blank.
I'm running setup.py as:
setup.py install --prefix ~/local
setup.py will complete with no errors and move main.py to ~/local/bin however when I run it I get the following error:
ImportError: No module named extern.mytest
Any idea what I'm doing wrong? Thanks!
The problem is that the module isn't under sys.path
and that's way it cannot be found by the import
statement.
In my case, the extern
module was installed under ~/local/lib/python2.7/site-packages/extern
. However, note that the installation path was arbitrarily set to ~/local
during the installation.
To fix that, you can set your PYTHONPATH
variable to the location where the module is installed or add that path to sys.path
in main.py
.
Alternatively, instead of:
setup.py install --prefix ~/local
use:
setup.py install --user
This will install in your user site packages directory (~/.local
in my platform) and python will be able to find the package without any problem. However, you'll probably need to change your PATH
environment variable to include ~/.local/bin
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With