pip install: How to force a specific package versi

2019-01-23 11:16发布

I'm trying to install Django 1.4.3, but when I execute pip install, pip keeps installing Django 1.5 version instead 1.4.3

sudo pip install -I Django==1.4.3

It returns:

Downloading/unpacking Django==1.4.3
  Running setup.py egg_info for package Django

    warning: no previously-included files matching '__pycache__' found under directory '*'
    warning: no previously-included files matching '*.py[co]' found under directory '*'
=== >>>> Requested Django==1.4.3, but installing version 1.5 <<<< ====
Installing collected packages: Django
  Found existing installation: Django 1.5
    Uninstalling Django:
      Successfully uninstalled Django
  Running setup.py install for Django

    warning: no previously-included files matching '__pycache__' found under directory '*'
    warning: no previously-included files matching '*.py[co]' found under directory '*'
    changing mode of /usr/local/bin/django-admin.py to 755
Successfully installed Django
Cleaning up...

but if I execute pip freeze, it keeps showing

Django==1.5

What am I doing wrong?

Thank you

标签: django pip
3条回答
该账号已被封号
2楼-- · 2019-01-23 11:49

Check your local cache and remove it can be help. I hava installed pymongo==2.5.2. To install pymongo==2.4.1, I remove the cache in /tmp/pip-build-root/pymongo.Then I install pymongo 2.4.1 successfully.

查看更多
何必那么认真
3楼-- · 2019-01-23 11:56

This could/should/can be helped by clearing the build dir for Django in pip. There is a bug for this, since version 1.1 see here for details

You can start checking for these folders here if you're on OS X or unix like systems:

~/.pip 
/tmp/pip-build-root (or pip-build-$USER, if you aren't running pip as root).

This is if you haven't specified a new build folder when you installed the first version of Django.

Good luck!

查看更多
一夜七次
4楼-- · 2019-01-23 12:02

As limelight says, you should empty your cache and build directories, or pass in a temporary clean location with the --download-cache and flag.

$ pip help install
[...]
--download-cache <dir>      Cache downloaded packages in <dir>.
-b, --build <dir>           Directory to unpack packages into and build in. The default in a virtualenv is "<venv path>/build". The default for global installs is
                          "<OS temp dir>/pip-build-<username>".

I'd like to warn any readers to not use sudo pip install to install Django. It installs Django system-wide. And changing the system-wide version could break system-packages that depend on it. For instance, Ubuntu MAAS and Cobbler depend on the system django package. These are typically services you don't want to break.

If you need a different version than the system-package, use virtualenv to isolate your dependencies from the system.

OP seems to be on OSX and I don't know of any server-wide Mac Django, but that may change. Consider installing python packages with sudo at par to changing the system-installed python with python 3; it might work for now, but have some paracetamol in stock, as you're in for some headaches.

查看更多
登录 后发表回答