8

I have a test setup file, which I made for a simple "hello world" script. I have a package named mytest which has a function hello. Now, I have a very simple setup.py. Everything works fine, if I just run python setup.py install. But if I want to install lib into home folder (python setup.py install --home=/home/blah), the package is not available anymore (running import mytest in python gives me ImportError: No module named mytest).

Should I add pth-file manually into site-packages folder? I tried it (with contents /home/blah/lib/python, where my package is put) and importing mytest worked fine. Shouldn't it be done automatically? Or have I missed something?

EDIT:

output of install:

ago@dellbert:~/py/mytest-0.1$ python setup.py install --home=/home/ago/py/
running install
running build
running build_py
copying src/mytest/mytest.py -> build/lib.linux-x86_64-2.6/mytest
running build_scripts
copying and adjusting src/main.py -> build/scripts-2.6
running install_lib
copying build/lib.linux-x86_64-2.6/mytest/mytest.py -> /home/ago/py//lib/python/mytest
byte-compiling /home/ago/py//lib/python/mytest/mytest.py to mytest.pyc
running install_scripts
copying build/scripts-2.6/main.py -> /home/ago/py//bin
changing mode of /home/ago/py//bin/main.py to 755
running install_egg_info
Removing /home/ago/py//lib/python/mytest-0.1.egg-info
Writing /home/ago/py//lib/python/mytest-0.1.egg-info

and setup.py:

from distutils.core import setup

setup(name='mytest',
      description='test',
      author='Ago',
      author_email='email',
      version='0.1',
      package_dir={'mytest': 'src/mytest'},
      packages=['mytest'],
      scripts=['src/main.py']
      )

Folder structure:

-src:
   -mytest:
       __init__.py
       mytest.py
    main.py
setup.py

main.py is just an executable which imports mytest and calls function to print hello world. But I have tried to just run import mytest in python to see, whether lib is installed.

1
  • Well, currently I have added mytest.pth file into site-packages with contents /home/ago/py/lib/python. But will, if anyone has a solution why my module/package isn't available with python setup.py install, I'm still interested. Thanks! Commented Dec 11, 2010 at 8:00

3 Answers 3

2

It seems python unified at least the parameters in Unix- and Windows environments. Looking at the python reference today (https://docs.python.org/2/install/index.html, Dec. 2017), it shows that in both OS you can use the --prefix=<head installation path>. Have a look on the reference, section "Alternate installation: Unix (the prefix scheme)" and "Alternate installation: Windows (the prefix scheme)". I just tested it with Oct2Py (Octave-to-Python converter), which was a trouble to install with easy_install or pip, but did the job this way quite well.

Your python package will be then in (assuming you use Python 2.7) <head installation path>/lib/python2.7/site-packages or <head installation path>/lib/python2.7/dist-packages.

Sign up to request clarification or add additional context in comments.

Comments

0

Use the following:

python setup.py install --prefix=<your path>

Comments

-1

I don't know if this code will help, I didn't tested it.
If your path is /src/lib/:

python setup.py install --install-lib /src/lib/
python setup.py install --user --prefix=

or

import sys
sys.path.append('your-path')

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.