-
Notifications
You must be signed in to change notification settings - Fork 0
Python Virtual Environments
A quick guide to running basic commands in pipenv.
Managing your application's dependencies in development is best handled in a virtual environment. This prevents different versions of a package clashing, and ensures that each app has the correct version of a package and dependency load.
To check if your Pipenv virtual environment is running, try the following methods:
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.
Run:
which pythonor 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.
If you are in the wrong virtual environment you may exit the current virtual environment.
Run:
exitor
deactivateNavigate 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-demoActivate the correct virtual environment
If you’re using pipenv, run:
pipenv shellTo check the dependencies installed in the virtual environment.
Check installed packages (if using Pipenv)
Run:
pip listIf it shows only system packages and not the ones from your Pipfile.lock, Pipenv might not be running.
If Pipenv is not running, start it with:
pipenv shellor run a command inside Pipenv:
pipenv run pythonInstall dependencies (if needed)
If you get a ModuleNotFoundError: No module named 'dotenv', install missing packages:
if using pipenv:
pipenv installRun
python manage.py runserverThese command should resolve any issues! 🚀
To check which packages are installed in your Pipenv virtual environment, use one of the following methods:
pipenv graph- Shows a dependency tree of installed packages.
pipenv run pip list- Displays a flat list of installed packages and their versions.
cat Pipfile- Shows declared dependencies (but not their installed versions).
cat Pipfile.lockor
pipenv lock -r- Lists exact versions of installed dependencies.
pipenv run pip show package_nameExample:
pipenv run pip show django- Displays details like version, location, dependencies, etc.
Let me know if you need more help! 🚀
To install packages using Pipenv, follow these steps:
pipenv install package_nameExample:
pipenv install django- This installs
djangoand adds it to yourPipfile.
pipenv install package_name --devExample:
pipenv install black --dev- This installs
blackonly for development (it won't be installed in production).
pipenv install requests numpy pandaspipenv install django==5.0.7- Installs Django version 5.0.7.
pipenv install -r requirements.txtpipenv install- Installs all dependencies listed in
Pipfile.lock.
pipenv uninstall package_nameExample:
pipenv uninstall djangoLet me know if you need more help! 🚀