force install package in virtualenv

Veröffentlicht:
Aleksandar Stajić
Aktualisiert am: 17. Mai 2023 um 12:53

Activating virtual environment:

  • source venv/bin/activate on Unix/Linux-based systems
  • venv\Scripts\activate on Windows

Forcing reinstall of the packages:

  • Upgrade can be done by adding: --upgrade or -U
  • Forcing reinstall of the packages can be done by adding: --force-reinstall

In your case (once the environment is activated):

python -m pip install -U --force-reinstall pack setuptools Django
  1. Deactivate and delete the old virtual environment
  2. Create new environment using python -m virtualenv venv for python 2 or python -m venv venv for python 3.x. That's the only point where you might want to use for example python3 or some absolute path instead. Later use the code as is.
  3. Activating the virtual environment source venv/bin/activate
  4. python -m pip install -U pip If you have issue with ImportError: No module named _internal than probably you are using an old version of pip. Do this: python -m pip install --upgrade pip
  5. python -m pip install -U --force-reinstall -r requirements.txt-U --force-reinstall is a bit of an overkill in case of fresh environment, but it will do no harm
  6. Go to the place where your manage.py is located and start the server using python manage.py runserver