How to install python package with a different name using PIP

前端 未结 10 2035
忘了有多久
忘了有多久 2020-12-09 07:56

When installing a new python package with PIP, can I change the package name because there is another package with the same name?

Or, how can I change the existing p

相关标签:
10条回答
  • 2020-12-09 08:04

    It's not possible to change "import path" (installed name) by specifying arguments to pip. All other options require some form of "changes to package":

    A. Use pip install -e git+http://some_url#egg=some-name: that way even if both packages have the same import path, they will be saved under different directories (using some-name provided after #egg=). After this you can go to the source directories of packages (usuaully venv/src/some-name) and rename some folders to change import paths

    B-C. Fork the repository, make changes, then install the package from that repository. Or you can publish your package on PyPI using different name and install it by name

    D. use pip download to put one of the packages in your project, then rename folders as you like

    0 讨论(0)
  • 2020-12-09 08:05

    Use virtualenv if you don't need both package for the same project. With virtualenv you can have different version of packages as well.

    Another way maybe the site-packages as mentioned already.

    https://virtualenv.pypa.io/en/stable/

    http://docs.python-guide.org/en/latest/dev/virtualenvs/#lower-level-virtualenv

    0 讨论(0)
  • 2020-12-09 08:10

    I think one way of going about this can be using

    pip download
    

    See the docs here. You can change the name of the package after it has been downloaded and then go about manually installing it. I haven't tested this but seems like it should work.

    0 讨论(0)
  • 2020-12-09 08:11

    I guess it depends if you need to update either of them. If you don't, then you can go to your site-packages folder, and rename the folder

    0 讨论(0)
  • 2020-12-09 08:12

    I had this problem with the libraries gmail and pygmail, they both want to install to PYTHONPATH/site-packages/gmail/. Clearly the pygmail package has an issue, it should be installing to pygmail folder, but they haven't made any updates in years.

    For an interim solution, I installed one (pygmail), then changed the folder names (gmail-->pygmail, and gmail-v#.dist-info-->pygmail-v#.dist-info), then installed the second one normally. Seems to work, as long as I don't try to update the first package. import gmail and import pygmail work as expected.

    0 讨论(0)
  • 2020-12-09 08:19

    Create a new virtualenv and then install the package on new virtualenv, with this you can have the different version of packages as well.

    0 讨论(0)
提交回复
热议问题