Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

installing python projects from git/github using pip #46

Open
ctb opened this issue Sep 21, 2022 · 2 comments
Open

installing python projects from git/github using pip #46

ctb opened this issue Sep 21, 2022 · 2 comments

Comments

@ctb
Copy link
Member

ctb commented Sep 21, 2022

By default, the Python package installer pip installs the latest version of packages from pypi.org, the Python package index. But what if you want to install an unreleased version (e.g. the latest version of sourmash), or a specific branch? Read on!

running pip inside a conda environment

I tend to do all of the below commands in a conda environment that contains python; then the installation is sandboxed in that conda environment. You can do the same thing with R - create and activate a conda environment containing r-base, then use standard R installation mechanisms to install. See this link for a conda environment that includes ggplot2 and tidyverse!

See this conda tutorial for some background and command lines for both Python and R.

Additional / extended details below!

installing directly from a branch

if you want to install a python project directly from a branch in a git repo, see solutions here:

https://stackoverflow.com/questions/20101834/pip-install-from-git-repo-branch

installing from a cloned git repo

you can also clone the repo and install directly with pip:

git clone https://github.com/dib-lab/genome-grist
cd genome-grist
python -m pip install .

this will install genome-grist from that directory. However, you will need to re-run pip install if you change the directory (update the branch, or whatever) and want the installation to reflect the new branch.

Is there a way around that? Yes! Read on!

installing from a cloned repo in 'editable' mode

I prefer installing projects in "editable" or "developer" mode, like so:

git clone https://github.com/dib-lab/genome-grist
cd genome-grist
python -m pip install -e .

This will tie the installation directly to the directory, so if you switch branches or edit files, the installed version will automatically reflect the changes.

(This is how I develop and test sourmash, charcoal, genome-grist, and spacegraphcats.)

@camillescott
Copy link
Member

Best practice for pip it to use python -m pip install [ARGS] rather than calling pip directly; this way, if pip is not installed in the virtual environment, it will fail directly, rather than potentially calling an externally installed pip and failing in unique and spectacular ways.

@ctb
Copy link
Member Author

ctb commented Sep 21, 2022

Best practice for pip it to use python -m pip install [ARGS] rather than calling pip directly

fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants