简体   繁体   中英

Install python package from local directory and remove said directory

I've written a python package that I would like to share with my coworkers, but I can't find how to install it alongside other packages installed through pip.

When issuing the following command, the package is successfully installed and I can use the package from anywhere on the system:

$ git clone git.adress.com/greatmodule.git
$ cd greatmodule
$ pip install .

However if someone delete the greatmodule/ directory, the package becomes unusable.

I'd like the module to be installed alongside other packages installed with pip , for instance under C:/Program Files/Python/Lib/site-packages in my case.

Is that possible / is it recommended?

There two better solutions that comes to mind instead of the one you are trying:

1. Install from repo

Pip supports installing a package from a git repository.

For example lets suppose you connect to your remote repository via ssh you can use the following (assuming:

pip3 install git+ssh://git@git.address.com/greatmodule.git

If you are using https to connect to repo:

pip3 install git+https://git.address.com/greatmodule.git

If using a specific branch:

pip3 install git+https://git.address.com/greatmodule.git@branch-name

2. Add package as submodule (ADVANCED)

Add repo as submodule:

git submodule add https://git.address.com/greatemodule.git

Then add submodule to PYTHONPATH

export PYTHONPATH=$PYTHONPATH:/directory_absolute_path

Then you can create source distribution (you'll need to package your app using setup.py that it should contain your packages names and versions)

python3 setup.py -q sdist --dist-dir=../package_directory

Then you can install the source distribution as normal package

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM