How can I install python packages in a virtual environment?

I am trying to use virtualenv. I used this command to install the package: pip install virtualenv Then I create a folder using this command: python -m venv venv Now I want to use django package in this environment. What should should do? I got this error message: Could not install packages due to an OSError: HTTPSConnectionPool ...

how to install any package in virtualenv

1 Answers

To install Python packages in a virtual environment created using virtualenv, you can follow these steps:

  1. Activate your virtual environment using: For Windows:
    ve\Scripts\activate

    For MacOS/Linux:

    source ve/bin/activate
  2. Install the desired package using pip:
    pip install django

    If you encounter an error related to HTTPSConnectionPool, it may be due to network restrictions or firewall settings. You can try using the --trusted-host option with pip to bypass this issue:

    pip install django --trusted-host pypi.python.org