Best way to install python packages locally for de

2019-03-09 02:39发布

Being new to the python games I seem to have missed out on some knowledge on how you can develop on a program but also keep it in your live environment.

Programs like gpodder can be run directly from the source checkout which is really handy however others want to be "installed" to run.

A lot of programs are distributed with a setup.py with instructions to run "python ./setup.py install" as root which will put stuff somewhere in your file-system. There are even install commands like "develop" which seem to hold the promise of what I want. So I tried:

export PYTHONPATH=/home/alex/python
python ./setup.py develop --install-dir=/home/alex/python

Which downloaded a bunch of stuff locally and seems magically ensure the application I'm hacking on is still being run out of the src tree. So I guess my roundabout question is is this the correct way of developing python code? How do things like easy_install and pip factor into this?

EDIT TO ADD

So I tried the following:

 python /usr/share/pyshared/virtualenv.py /home/alex/src/goobook
 cd /home/alex/src/goobook/googbook.git
 /home/alex/src/goobook/bin/python ./setup.py develop

And finally linked the program in question to my ~/bin

 cd /home/alex/src/goobook
 linkbin.pl bin/goobook

However invocation throws up a load of extra chatter which seems to imply it's wrong:


17:17 alex@socrates/i686 [goobook] >goobook --help
/home/alex/bin/goobook:5: UserWarning: Module pkg_resources was already imported from        /home/alex/src/goobook/lib/python2.5/site-packages/setuptools-0.6c8-py2.5.egg/pkg_resources.py, but /home/alex/src/goobook/lib/python2.5/site-packages/distribute-0.6.10-py2.5.egg is being added to sys.path
  from pkg_resources import load_entry_point
/home/alex/bin/goobook:5: UserWarning: Module site was already imported from /home/alex/src/goobook/lib/python2.5/site.pyc, but /home/alex/src/goobook/lib/python2.5/site-packages/distribute-0.6.10-py2.5.egg is being added to sys.path
  from pkg_resources import load_entry_point

4条回答
仙女界的扛把子
2楼-- · 2019-03-09 03:39

The best way to develop Python apps with dependencies is to:

1) Download desired version of the python interpreter.

2) Install and use buildout (http://www.buildout.org/).

Buildout is something like Maven for Java (will fetch all needed packages automatically).

This way your Python interpreter will not be polluted by third party packages (this is important if you will be running developed application on other machines). Additionally you can integrate buildout with virtualenv package (this allows you to create virtual python interpreters for each project).

查看更多
Root(大扎)
3楼-- · 2019-03-09 03:40

Install:

http://pypi.python.org/pypi/virtualenv

to set up a localized virtual environment for your libraries, and:

http://pypi.python.org/pypi/setuptools

i.e. "easy_install" to install new things.

查看更多
我想做一个坏孩纸
4楼-- · 2019-03-09 03:42

The Python Packaging User Guide, which "aims to be the authoritative resource on how to package, publish and install Python distributions using current tools", recommends using pip to install in "development mode":

pip install -e <path>

Thus in the root directory of your package you can simply

pip install -e .

See installing from a local source tree.

查看更多
劫难
5楼-- · 2019-03-09 03:43

Virtualenv allows you to work in completely independent and isolated Python environments. It will let you easily create multiple environments which have different Python packages installed or different versions of a same package. Virtualenv also lets you easily switch between your different environments.

As of 2012, the de facto preferred tool for package management in Python is pip rather than setuptools. Pip is able to handle dependencies and to install/uninstall globally or inside a virtual environment. Pip even comes out-of-the-box with virtualenv.

Python 3

Also worth mentioning is the fact that virtual environments are becoming a part of Python itself in release 3.3, with the implementation of PEP 405.

查看更多
登录 后发表回答