Prepend the url prefix git+ (See VCS Support):
Use with AIpip install git+https://github.com/tangentlabs/django-oscar-paypal.git@issue/34/oscar-0.6
And specify the branch name without the leading /.
Prepend the url prefix git+ (See VCS Support):
Use with AIpip install git+https://github.com/tangentlabs/django-oscar-paypal.git@issue/34/oscar-0.6
And specify the branch name without the leading /.
Using pip with git+ to clone a repository can be extremely slow (test with https://github.com/django/django@stable/1.6.x for example, it will take a few minutes). The fastest thing I've found, which works with GitHub and BitBucket, is:
Use with AIpip install https://github.com/user/repository/archive/branch.zip
which becomes for Django master:
Use with AIpip install https://github.com/django/django/archive/master.zip
for Django stable/1.7.x:
Use with AIpip install https://github.com/django/django/archive/stable/1.7.x.zip
With BitBucket it's about the same predictable pattern:
Use with AIpip install https://bitbucket.org/izi/django-admin-tools/get/default.zip
Here, the master branch is generally named default.
This will make your requirements.txt installing much faster.
Some other answers mention variations required when placing the package to be installed into your requirements.txt. Note that with this archive syntax, the leading -e and trailing #egg=blah-blah are not required, and you can just simply paste the URL, so your requirements.txt looks like:
Use with AIhttps://github.com/user/repository/archive/branch.zip
python - How to install from a downloaded git repository - Stack Overflow
python - Is it possible to use pip to install a package from a private GitHub repository? - Stack Overflow
Python Modules: Cloning from GitHub vs pip install
python - How can I install from a git subdirectory with pip? - Stack Overflow
The easiest way to do this is most likely by first downloading using git and then installing with pip e.g.
You can clone the repo again to assure non of your previous changes interfere with the installation.
git clone https://github.com/xyz/repo-name.git repo_name
Then cd into your repo and install:
cd repo_name
pip install -e .
Note that any changes that will be made to the repo will be automatically updated in the your environment due to the editable (-e) tag.
Direct answer to your question:
First, unzip the downloaded file with :
!unzip repo_name.zip -d path/to/folder
Then, navigate to the repo and run the installation script.
cd path/to/folder/repo_name
pip install -e .
You can use the git+ssh URI scheme, but you must set a username. Notice the git@ part in the URI:
pip install git+ssh://git@github.com/echweb/echweb-utils.git
Also read about deploy keys.
PS: In my installation, the "git+ssh" URI scheme works only with "editable" requirements:
pip install -e URI#egg=EggName
Remember: Change the : character that git remote -v prints to a / character before using the remote's address in the pip command:
$ git remote -v
origin git@github.com:echweb/echweb-utils.git (fetch)
# ^ change this to a '/' character
If you forget, you will get this error:
ssh: Could not resolve hostname github.com:echweb:
nodename nor servname provided, or not known
As an additional technique, if you have the private repository cloned locally, you can do:
pip install git+file://c:/repo/directory
More modernly, you can just do this (and the -e will mean you don't have to commit changes before they're reflected):
pip install -e C:\repo\directory
So I've selected a Python project to contribute to from GitHub. I use the module that I've selected and am familiar with some portions of it. It would be cool if I were to complete my contribution and have it be accepted.
I have a few questions (are unfortunately very basic!) that I'd love some help with.
I'll start with a set-up question.
After cloning the project and getting a local copy, I can't import some of the modules even though it's in my PYTHONPATH. I see that class I want to import was downloaded from GitHub as <blah>.c.
When I try in another virtualenv python with said module installed via pip, the import work.
Does pip do any compilation? Do I need to do this manually when working with GitHub projects?
Is there a recommended way of doing this?
There is a pull request regarding this feature, and it seems to have been merged to develop branch a month ago. The syntax is the following:
pip install -e "git+https://git.repo/some_repo.git#egg=$NAME_OF_PACKAGE&subdirectory=$SUBDIR_IN_REPO" # install a python package from a repo subdirectory
We probably have to wait for a while until it gets merged to master and is distributed.
UPDATE: This is now available and documented at https://pip.pypa.io/en/stable/cli/pip_install/#vcs-support as follows:
For projects where setup.py is not in the root of project, "subdirectory" component is used. Value of "subdirectory" component should be a path starting from root of the project to where setup.py is located.
So if your repository layout is:
- pkg_dir/ - setup.py # setup.py for package ``pkg`` - some_module.py - other_dir/ - some_file - some_other_fileYou'll need to use
pip install -e "vcs+protocol://repo_url/#egg=pkg&subdirectory=pkg_dir"
Note: Make sure to surround it with quotes otherwise subdirectory won't work.
It's been already stated in one of the comments under the correct answer, but just to highlight this issue: when executing this from Linux command line, you must escape the &-character since ampersand is telling the command line to run a command in background:
git+https://git.repo/some_repo.git#egg=version_subpkg\&subdirectory=repo
Notice the backslash before the ampersand. The escaping behaviour might depend on the Linux distro; I'm not an expert.
If you ignore this, you might run into a cryptic error like the following:
bash: (...) command not found
Using GitPython will give you a good python interface to Git.
For cloning a new repository you can use clone_from function:
Use with AIfrom git import Repo # pip install gitpython
Repo.clone_from(git_url, repo_dir)
See the GitPython Tutorial for examples on using the Repo object.
Note: GitPython requires git being installed on the system, and accessible via system's PATH.
There is GitPython. Haven’t heard of it before and internally, it relies on having the git executables somewhere; additionally, they might have plenty of bugs. But it could be worth a try.
How to clone:
Use with AIimport git # pip install gitpython
git.Git("/your/directory/to/clone").clone("git://gitorious.org/git-python/mainline.git")
(It’s not nice and I don’t know if it is the supported way to do it, but it worked.)