Install Python package from GitHub using PyCharm

2019-01-19 00:15发布

问题:

I created a VirtualEnv in PyCharm to install my Python packages. I wanted to install this fork of the django project from GitHub.

https://github.com/django-nonrel/django

For packages available from PyPI I would normally use the built in search tool in PyCharm but I'm not sure how to correctly install it into the VirtualEnv within PyCharm from GitHub. Would anyone know how to do this?

回答1:

I personally would suggest cloning the repository to a local folder

git clone https://github.com/django-nonrel/django.git my_folder

Then install it manually:

cd my_folder
python setup.py build
python setup.py install

I wouldn't recommend using PyCharm to install the packages, since you will become dependent on it... Use pip instead, wich is the tool pycharm uses anyway



回答2:

The following worked for me with PyCharm Community Edition 2018.1 on Xubuntu 16.04:

After loading the project (which was associated with the virtual environment that I wanted to update), I opened PyCharm's Terminal window (AltF12, or View > Tool Windows > Terminal) and then used the command

pip install git+https://github.com/v-chojas/pyodbc@unicodecolumnsize

to install pyodbc from the "unicodecolumnsize" branch of the fork maintained by user v-chojas.

Once the install was completed the package showed up in the Project Interpreter widow

On OSX+PyCharm 2018.1 needed to restart PyCharm to pick up the change and recognize the imports from the newly installed packages.



回答3:

I was struggling to find a way to do this within the PyCharm UI, but it is possible through the integrated Python console:

  1. Load your project with the appropriate VE
  2. Under the Tools dropdown, click Python Console
  3. Then use pip from within the console:

    import pip
    pip.main(['install','packagename'])
    


回答4:

Alternatively, in console:

pip install -e git+https://github.com/%%#egg=Package