Skip to content

Python Virtual Environments

Edward Baitsewe edited this page Feb 23, 2025 · 3 revisions

Python Virtual Environments

To check if your Pipenv virtual environment is running, try the following methods:

1. Check if Pipenv shell is active

Run:

echo $VIRTUAL_ENV
  • If it prints a path (e.g., /home/user/.local/share/virtualenvs/myproject-xxxx), Pipenv is running.
  • If it's empty, Pipenv is not active.

Alternatively, you can try:

pipenv --venv
  • If the command returns a path, the environment exists.
  • If you see No virtualenv has been created, run pipenv shell to start it.

2. Check if Python is using Pipenv's virtual environment

Run:

which python

or on Windows:

where python
  • If it points to a path inside .venv or virtualenvs/, Pipenv is running.
  • If it points to the system Python (/usr/bin/python or C:\Python), Pipenv is not active.

3. Deactivate Virtual Environment

If you are in the wrong virtual environment you may exit the current virtual environment.

Run:

exit

or

deactivate

4. Activate The Correct Virtual Environment

Navigate to the correct project directory

If you're not already there, run a command to navigate to the correct directory:

cd ~/OneDrive/Coding\ Projects/docker-django-demo

Activate the correct virtual environment

If you’re using pipenv, run:

pipenv shell

5. Check Installed Dependencies

To check the dependencies installed in the virtual environment.

Check installed packages (if using Pipenv)

Run:

pip list

If it shows only system packages and not the ones from your Pipfile.lock, Pipenv might not be running.

6. Check Installed Dependencies

If Pipenv is not running, start it with:

pipenv shell

or run a command inside Pipenv:

pipenv run python

7. Install Dependencies

Install dependencies (if needed)
If you get a ModuleNotFoundError: No module named 'dotenv', install missing packages: if using pipenv:

pipenv install

8. Run Django Server

Run

python manage.py runserver

These command should resolve any issues! 🚀

Clone this wiki locally