Thursday, October 6, 2022

[SOLVED] how to install python packages locally inside virtual environment

Issue

I am trying to install packages from my requirements.txt file but I am getting this error, it's interesting because I don't have any project dependency as such and I have already ran

pip install -r requirements.txt

error I am getting

File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'django_sass'

I want to install these dependencies such that they should be local only to the project I am working on, any idea how to achieve that ?


Solution

First, create a virtual environment for installing it for project-specific. For that, you will require virtualenv package. You can download it using:

pip install virtualenv

Once done, move to your project directory and create virtualenv using:

virtualenv <your_environment_name> 

Like if you wants to create environment named my_env. The command goes like:

virtualenv my_env 

Now activate your virtualenv. If you are on windows, activate using:

.\my_env\Scripts\activate

If you are on Linux:

source my_env/bin/activate

Now install your requirements.txt using:

pip install -r requirements.txt


Answered By - Vishal Teotia
Answer Checked By - Cary Denson (WPSolving Admin)