Editing a python package - python

The question is really simple:
I have a python package installed using pip3 and I'd like to tweak it a little to perform some computations. I've read (and it seems logical) that is very discouraged to not to edit the installed modules. Thus, how can I do this once I downloaded the whole project folder to my computer? Is there any way to, once edited this source code install it with another name? How can I avoid mixing things up?
Thanks!

You can install the package from its source code, instead of PyPi.
Download the source code - do a git clone <package-git-url> of the package
Instead of pip install <package>, install with pip install -e <package-directory-path>
Change code in the source code, and it will be picked up automatically.

Related

Python setup.py develop vs install

Two options in setup.py develop and install are confusing me. According to this site, using develop creates a special link to site-packages directory.
People have suggested that I use python setup.py install for a fresh installation and python setup.py develop after any changes have been made to the setup file.
Can anyone shed some light on the usage of these commands?
python setup.py install is used to install (typically third party) packages that you're not going to develop/modify/debug yourself.
For your own stuff, you want to first install your package and then be able to frequently edit the code without having to re-install the package every time — and that is exactly what python setup.py develop does: it installs the package (typically just a source folder) in a way that allows you to conveniently edit your code after it’s installed to the (virtual) environment, and have the changes take effect immediately.
Note: It is highly recommended to use pip install . (regular install) and pip install -e . (developer install) to install packages, as invoking setup.py directly will do the wrong things for many dependencies, such as pull prereleases and incompatible package versions, or make the package hard to uninstall with pip.
Update:
The develop counterpart for the latest python -m build approach is as follows (as per):
From the documentation. The develop will not install the package but it will create a .egg-link in the deployment directory back to the project source code directory.
So it's like installing but instead of copying to the site-packages it adds a symbolic link (the .egg-link acts as a multiplatform symbolic link).
That way you can edit the source code and see the changes directly without having to reinstall every time that you make a little change. This is useful when you are the developer of that project hence the name develop. If you are just installing someone else's package you should use install
Another thing that people may find useful when using the develop method is the --user option to install without sudo. Ex:
python setup.py develop --user
instead of
sudo python setup.py develop

How to install many python extensions in one step

Is it possible to collect many Python extensions an install them in one step? I have a Python build environment for an open source project that often needs to be recreated on multiple machine. It's a pain to double click through a bunch of python extension exes every time we need to do this.
Ideally I'd like to package a complete build environment, Python, extensions, system environment variables, and all, into a one step install process. But a single step extension install would also be helpful. Is this possible?
Yes, you can do that... do you have pip(python indexed package) installed in your system?
if not, then install it... and put all the extensions into a single text file... say requirements.txt...
This is done by running
pip freeze > requirements.txt
then by using pip you can install it... by using this command...
pip install -r requirements.txt...
it will install all the extensions mentioned in the file...
you can find the pip package here pip
might help you...
You can with Distribute define dependencies of a package, and easy_install or pip will install all dependencies when you ask to install the package.

Using pip to install single-file python modules

I'm wondering if there's a way to "install" single-file python modules using pip (i.e. just have pip download the specified version of the file and copy it to site-packages).
I have a Django project that uses several 3rd-party modules which aren't proper distributions (django-thumbs and a couple others) and I want to pip freeze everything so the project can be easily installed elsewhere. I've tried just doing
pip install git+https://github.com/path/to/file.git
(and tried with the -e tag too) but pip complains that there's no setup.py file.
Edit: I should have mentioned - the reason I want to do this is so I can include the required module in a requirements.txt file, to make setting up the project on a new machine or new virtualenv easier.
pip requires a valid setup.py to install a python package. By definition every python package has a setup.py... What you are trying to install isn't a package but rather a single file module... what's wrong with doing something like:
git clone git+https://github.com/path/to/file.git /path/to/python/install/lib
I don't quite understand the logic behind wanting to install something that isn't a package with a package manager...

PIP install a Python Package without a setup.py file?

I'm trying to figure out how I can install a python package that doesn't have a setup.py file with pip. (package in question is http://code.google.com/p/django-google-analytics/)
Normally I would just checkout the code from the repo and symlink into my site-packages, but I'm trying to get my whole environment frozen into a pip requirements file for easy deployment and testing.
Any ideas?
Fork the repo and add a working setup.py. Then send a pull request to the author.
Oh, it's on Google Code. Well then, file a bug and post a patch.
If the author refuses to make their code into an installable Python distribution (never happened to me), just host your fork somewhere and put that in your requirements file.
You can't. PIP installs Python packages. That's not a Python package. I've heard that the Django community in general doesn't make much packages, which makes things like what you are trying to do tricky. But that could be wrong.
If you want to freeze your environment you might want to look into Buildout. Other options in this case is to use an svn:external.

Python package install using pip or easy_install from repos

The simplest way to deal with python package installations, so far, to me, has been to check out the source from the source control system and then add a symbolic link in the python dist-packages folder.
Clearly since source control provides the complete control to downgrade, upgrade to any branch, tag, it works very well.
Is there a way using one of the Package installers (easy_install or pip or other), one can achieve the same.
easy_install obtains the tar.gz and install them using the setup.py install which installs in the dist-packages folder in python2.6. Is there a way to configure it, or pip to use the source version control system (SVN/GIT/Hg/Bzr) instead.
Using pip this is quite easy. For instance:
pip install -e hg+http://bitbucket.org/andrewgodwin/south/#egg=South
Pip will automatically clone the source repo and run "setup.py develop" for you to install it into your environment (which hopefully is a virtualenv). Git, Subversion, Bazaar and Mercurial are all supported.
You can also then run "pip freeze" and it will output a list of your currently-installed packages with their exact versions (including, for develop-installs, the exact revision from the VCS). You can put this straight into a requirements file and later run
pip install -r requirements.txt
to install that same set of packages at the exact same versions.
If you download or check out the source distribution of a package — the one that has its "setup.py" inside of it — then if the package is based on the "setuptools" (which also power easy_install), you can move into that directory and say:
$ python setup.py develop
and it will create the right symlinks in dist-packages so that the .py files in the source distribution are the ones that get imported, rather than copies installed separately (which is what "setup.py install" would do — create separate copies that don't change immediately when you edit the source code to try a change).
As the other response indicates, you should try reading the "setuptools" documentation to learn more. "setup.py develop" is a really useful feature! Try using it in combination with a virtualenv, and you can "setup.py develop" painlessly and without messing up your system-wide Python with packages you are only developing on temporarily:
http://pypi.python.org/pypi/virtualenv
easy_install has support for downloading specific versions. For example:
easy_install python-dateutil==1.4.0
Will install v1.4, while the latest version 1.4.1 would be picked if no version was specified.
There is also support for svn checkouts, but using that doesn't give you much benefits from your manual version. See the manual for more information above.
Being able to switch to specific branches is rarely useful unless you are developing the packages in question, and then it's typically not a good idea to install them in site-packages anyway.
easy_install accepts a URL for the source tree too. Works at least when the sources are in Subversion.

Categories

Resources