October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Create a Python Virtual Environment on a Linux VPS

Install the venv package, create .venv with the intended Python interpreter, activate it, install dependencies with the environment's pip, and deactivate when finished.
Length9 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

On an Ubuntu or Debian Linux VPS, install the distribution’s venv package, create an environment in your project directory, activate it, and install your application packages through that environment’s pip:

sudo apt update
sudo apt install python3-venv
cd ~/projects/myproject
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
# leave the environment when finished
deactivate

The .venv directory keeps project packages separate from the VPS’s system Python. The Python interpreter used in the creation command determines the environment’s Python version.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What a virtual environment changes on a VPS

A Python virtual environment is an isolated directory containing the interpreter links, activation scripts, configuration and package-installation tools for one project. It does not create a second operating system or a separate VPS. Instead, activation changes your shell’s PATH so commands such as python and pip resolve to the environment first.

This separation matters on a server because application dependencies can be installed without altering packages used by the operating system or another application. You can have different projects use different dependency sets, remove one project’s environment without removing system Python, and reproduce an application’s setup from a requirements file.

#1 Best Overall
Sale
Gaoye Blue Light Blocking Glasses
  • BLUE LIGHT BLOCKING GLASSES: Our blue light glasses for women boast UV400 protection, blocking harmful blue rays from computer screens. With these bluelight glasses women, you can enjoy gaming, reading, or watching TV with no worries of eye strain.
  • EYE RELIEF: Our blue light glasses are engineered to reduce blurry vision or strain caused by prolonged screen time. These womens blue light glasses aid in better sleep by preventing blue light from disrupting your natural sleep cycle, helping you fall asleep faster and enjoy a more restful night's sleep, making them the perfect christmas present.
  • COMFORTABLE: Crafted from durable material, our trendy blue light glasses for woman or blue light glasses men ensure long-lasting comfort. The high-transmittance lenses accessories, gamer gifts for men, help keep your eyes relaxed. Perfect stocking stuffers, gifts for gamers men, christmas gifts for men, halloween costumes.
  • LIGHTWEIGHT: These clear blue light glasses feature a lightweight frame, meaning they’ll stay comfy for long-term wear. Perfect as blue blockers glasses for women or mens blue light glasses, these non-prescription fake glasses for men can be worn throughout the day. The blue light blocking glasses women feature polycarbonate HD lenses, which are anti-reflective and restore true color.
  • WORRY-FREE PURCHASE: If you experience any issues, our support team is ready to assist you quickly. These are the perfect costume glasses for cosplay dressing up.

Python’s official venv documentation describes the module and its command-line options. The commands below use a POSIX shell such as Bash and focus on Ubuntu and Debian package names; other Linux distributions package the module differently.

Check the VPS before creating anything

Confirm the operating system family

The package command in this guide is for Ubuntu and Debian. Check the distribution before running it:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
cat /etc/os-release

If the output identifies Ubuntu or Debian, continue with apt. The supplied procedure does not establish package names for RHEL, Fedora, Alpine or other distributions, so use that distribution’s Python packaging documentation rather than assuming python3-venv is the correct name.

Find the Python interpreter you intend to use

Check the available interpreter and its version:

python3 --version
command -v python3

The command you run later controls the version inside the environment. Running python3.11 -m venv .venv, for example, creates an environment from the python3.11 interpreter if that executable exists. Running python3 -m venv .venv uses whichever interpreter the python3 command currently selects.

Choose a project directory

Create or enter the directory that should own the environment. A hidden directory named .venv is conventional, while venv is also common:

mkdir -p ~/projects/myproject
cd ~/projects/myproject

The environment can live elsewhere, such as ~/projects/myproject/venv. Use one location consistently in activation, deployment scripts and documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Install the venv package on Ubuntu or Debian

Ubuntu and Debian commonly split the venv module into a package that is not present in a minimal server installation. Install it before creating the environment:

sudo apt update
sudo apt install python3-venv

On a system where the default python3 is a particular minor release, the matching versioned package may be needed when the unversioned package does not provide the module. For example, an installation using Python 3.x can require its corresponding python3.x-venv package. Use the exact interpreter you plan to run and the package version supplied by your distribution.

Rank #2
Windex Gaming Cleaning Wipes, Pre-Moistened Wipes to Instantly Clean all Gaming Gear and Electronics, Resealable Packaging for a Freshness Lock, 25 count (Pack of 1)
  • WINDEX GAMING WIPES: effortlessly clean all your gaming gear and gaming electronics in one easy step with our new Windex Gaming Wipes
  • AMMONIA FREE: our ammonia-free formula is safe to use on all of your favorite gaming equipment like consoles, headsets, controllers, screens, keyboards, and more
  • PRE-MOISTENED WIPES: each wipe instantly removes dust, dirt, and stubborn smudges and fingerprints leaving a streak-free shine
  • ANTI-STATIC: great for cleaning and wiping down your gaming gear and electronics leaving behind no visible residue
  • COMPACT RESEALABLE PACKAGE: store your pack of Windex Gaming Wipes anywhere in your home for whenever a quick and easy wipedown is needed

After installation, retry the creation command from the project directory:

python3 -m venv .venv

Create the environment

The standard command

From the project directory, run:

python3 -m venv .venv

The command creates the target directory and its parents when necessary. A successful environment normally contains:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • pyvenv.cfg, whose home setting points to the Python installation used to create the environment.
  • A bin directory on Linux containing the environment’s activation scripts and a copy or symlink of the interpreter.
  • The files needed for the environment’s package installer, unless you explicitly disable pip bootstrapping.

If .venv already exists, do not overwrite it casually. Decide whether it belongs to this project, back it up, or remove and recreate it. Recreating an environment removes its installed packages, so preserve a requirements file or another dependency record first.

Create an environment with a specific Python version

When multiple interpreters are installed, name the one you want explicitly:

python3.11 -m venv .venv

Substitute the executable that is actually available on the VPS. Verify the resulting version after activation rather than relying only on the directory name.

Activate and verify the environment

Activate in the current shell

For Bash and other compatible POSIX shells, run:

source .venv/bin/activate

The shell prompt usually gains the environment name in parentheses, such as (.venv). The prompt is only a visual cue; verify the executable paths directly:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
command -v python
command -v pip
python --version
python -m pip --version

The paths should point inside your project’s .venv/bin directory. Using python -m pip is a reliable way to ask the selected interpreter to run its matching pip, especially when a VPS has several Python installations.

Activation is per shell session

Activation changes the environment variables of the current shell. A new SSH session, a new terminal, a different user, or a separately launched script does not automatically inherit it. Activate again in each interactive shell, or call the environment’s interpreter explicitly in automation:

Rank #3
Sale
LISEN Cell Phone Stand Phone Holder for Desk, Office Decor Gadgets for Men
  • Ergonomic & Adjustable Design: Fight "text neck" and improve your posture. Designed for comfort, it offers an adjustable height (7.1in-8.5in) (1.4in adjustable range) and angle (5°-85°) Please note: cell phone stand is only 9 inches tall—the length of a standard pencil
  • Without blocking subtitles Perfect for office desk Tiktok Face Time Zoom video—this is the ultimate kitchen desk essential for phones! Perfect viewing experience while reducing neck back strain, A must-have for gamers streamers desk, and anyone who values both style and support!
  • Sleek & Stable Design fits Otterbox Case: Say goodbye to bent cables, tangles, and tip-overs! LISEN’s stylish adjustable desk phone holder features a built-in charging hole and smart cable management, keeping your phone secure and your workspace clutter-free cool gadgets for men
  • ANTI-SLIP DESIGN free hands: The under 10.00 items easy gadgets back and the bottom of this kitchen essentials for women are fully covered by anti-skid silicone, which LISEN stand up desk decor can provide maximum protection device from any scratches and slides
  • Your Perfect Viewing Companion:If your product arrives damaged or breaks within 365 days, reach out to LISEN for a quick and hassle-free solution. Struggling with assembly, like tightening the screw? We’ve got your back! Your experience matters to us. (Product including: phone Holder stand*1, screw*1, hexagon screwdriver*1, specification*1)
~/projects/myproject/.venv/bin/python -m pip install -r requirements.txt
~/projects/myproject/.venv/bin/python app.py

This explicit form avoids depending on a prompt or on whether a shell startup file happened to activate an environment.

Install project dependencies safely

Upgrade pip only inside the environment

Once the prompt is activated, an optional upgrade affects the environment’s pip:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
python -m pip install --upgrade pip

Check the path and version if you are unsure which pip will run. Do not use sudo pip for application packages: elevated installation targets the system Python and defeats the isolation you created.

Install a requirements file

If the project supplies requirements.txt, install it with the active interpreter:

python -m pip install -r requirements.txt

Packages are installed into the environment rather than the system-wide site-packages location. Keep the requirements file with the project so a newly created environment can be populated with the same declared dependencies.

Install an individual package

For a one-off dependency, use the same interpreter-qualified pattern:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
python -m pip install package-name

Replace package-name with the package your application requires. The command must be run after activation, or use the full path to .venv/bin/python extbackslash{} -m pip when working non-interactively.

Leave the environment

When you finish working on the project, run:

deactivate

The command restores the previous shell PATH. It does not delete .venv or uninstall anything. You can activate the same directory again later with source .venv/bin/activate.

Rank #4
Ledagic IC+RGBW USB Powered Led Light Bar with App & Remote Control, 2 Pack
  • Easy Installation: Our gaming lights have been designed to enhance your entertainment experience. Simply position the led light bar next to your TV or game console to create a game room environment with ease. They come with USB power and a 60 inch cord for direct mounting and mobility
  • Audio Syncing & Extensive Mode: The built-in high-sensitivity music sensor allows you to sync the TV led lights to your favorite music. Lights react and move to the beat of music, film and game audio, creating an incredible immersive sound and light experience – and all without the need for an additional hub. You can choose from 64+ patterns, including strobe, illusion, jump, energy, gradient, running, chasing, fluttering mode etc. Each mode can be applied to different scenes
  • 64+ Chasing IC+RGB & W Effect: The independent control design of IC+RGB and white all-in-one multifunctional rgbw led bar lights monitor backlight allows you to easily switch the led lights for desk between IC+RGB and white to enjoy a variety of lighting effects, you can choose white lighting mode with high brightness for better illumination when working, etc. Choose IC+RGB lighting mode when you need to create an entertaining atmosphere for the light show, 16 million colours of Color changing rgb light bar let you dance to the beat and create a dynamic party atmosphere
  • Dynamic and Dimmable Lights: 1%-full brightness free brightness adjustment gives you the flexibility to adjust dimmable led light bar for room decorations or a variety of occasions
  • USB Powered: USB light bars for room can be powered by powernank, usb charger, TV, Monitor, laptop PC mainframe, making behind TV led lighting bar easy to install in any location.TV led lights are powered by the TV usb interface / PC mainframe, can be turned on/off synchronously with TV / PC

Useful creation options

The Python 3.10 usage text lists several options. Run python3 -m venv --help on the VPS to see the options supported by the exact Python version installed there.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Option Effect When to use it
--upgrade Upgrade an existing environment’s core files to match the interpreter that runs the command. When the base interpreter was upgraded and you need to update an existing environment; it does not replace a deliberate rebuild.
--without-pip Do not bootstrap pip in the new environment. Only when you have a specific reason to manage pip separately. Ordinary application setups should omit it.
--prompt PROMPT Use a custom prompt label instead of the directory name. Useful when several environments have similar directory names.
--upgrade-deps Upgrade the environment’s core dependencies after creation. Use only if this option is supported by your installed Python and your setup policy allows the resulting dependency changes. It is a venv option, not an ensurepip option.
--system-site-packages Allow the environment to see packages installed system-wide. Only when the application intentionally depends on system packages. It reduces isolation and can make dependency behavior harder to reproduce.

A typical customized command therefore looks like:

python3 -m venv --prompt myproject .venv

Do not add options merely because they exist. The plain command is easier to understand and gives the project the strongest separation from system packages.

Understand what is and is not isolated

The environment isolates Python packages and selects a particular interpreter installation. It does not isolate the Linux user, filesystem permissions, network access, database, service manager or operating-system libraries. Your VPS account still needs permission to read the project and write to .venv. A package that depends on an external system library may still require that library to be installed through the operating system’s package manager.

Similarly, activation is not a security boundary. It is a shell convenience that changes command lookup. A script can bypass activation by invoking .venv/bin/python directly, and a different user cannot use the environment unless filesystem permissions allow it.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot the common creation errors

No module named venv

This error generally means the distribution’s venv package is missing. On Ubuntu or Debian, install it and retry:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo apt update
sudo apt install python3-venv
python3 -m venv .venv

If you are invoking a versioned interpreter, make sure the installed package matches that interpreter’s minor version. Installing a package for one Python version does not guarantee that another version can import venv.

ensurepip is not available

During creation, venv normally bootstraps pip through ensurepip unless --without-pip is used. An error saying that ensurepip is unavailable means the Python build does not provide that component. On Ubuntu, install the matching versioned venv package, then run the creation command again:

sudo apt install python3.X-venv
python3.X -m venv .venv

Replace 3.X with the minor version shown by python3.X --version. Do not treat --without-pip as a fix if the project needs pip; that option intentionally suppresses pip bootstrapping.

Best Value
Sale
HUANUO FlowLift™ Dual Monitor Stand, Fully Adjustable Gaming Monitor Desk Mount for 13–32″ Computer Screens, Full Motion VESA 75x75/100x100 with C-Clamp & Grommet Base, Each Arm Holds 4.4 to 19.8 lbs
  • Compatible with Wide Screens - To ensure compatibility with the dual monitor mount, your each monitor must meet three conditions at the same time: First, computer screens size range: 13 to 32 inches. Second, screen weight range: 4.4 to 19.8 lbs. Third, the back of the monitor screen must have VESA mounting holes with a pitch of 75x75mm or 100x100mm.
  • Regarding the compatibility with desks - Your desk must meet three conditions at the same time: First, desk material: Only wooden desks are recommended, plastic or glass desks cannot be used. Second, desk thickness range: 0.59" - 3.54". Third, the bottom of the desk should not have any cross beams or panels, as this will interfere with installation. We recommend carefully checking that your desk and monitors meets all above conditions before purchasing.
  • Dual C-Clamp Hold - Worried your dual monitors might wobble or slip? Our upgraded base uses a larger platform plus a dual C-clamp structure to lock the dual monitor arm firmly to your desk. Each arm safely keeps your screens steady while you type, click and game—no shaking, no sliding, just a clean and secure setup you can trust every day. It also provides Grommet Mounting installation choice, both options ensure stable and secure fixation for your 0.59" - 3.54" desk.
  • Full-Motion Adjustment For Comfortable View - Pull the screen closer when you’re deep in a spreadsheet, push it back to watch videos, or rotate to portrait for coding — moving everything smoothly with just one hand. The monitor stand offers +85°/-50° tilt, ±90° swivel and 360° rotation. Raise your monitor up to 15.75″ to support a healthy sitting posture. Whether you’re working from home, gaming through the night, or switching between video calls and documents, getting the screens to your natural line of sight helps relieve neck, shoulder and back strain so you can stay focused longer with less fatigue.
  • Keep Your Desk Organized: By lifting both screens off the desktop, this dual monitor stand opens up valuable space for your keyboard, notebook, docking station or a simple, clutter-free work area. Built-in cable management guides wires along the arms, keeping cords out of sight and out of the way. Enjoy a tidy, modern workstation that looks as good as it feels to use.

The prompt did not change after activation

A prompt label is not guaranteed by every shell configuration. Check the actual paths:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
source .venv/bin/activate
command -v python
python -m pip --version

If the paths do not contain .venv/bin, you may be in the wrong directory, have activated a different environment, or be using a shell that does not support the command as written. Use the activation script appropriate to your shell and verify with command -v rather than relying on the prompt.

python and pip still select the system installation

Activation must run in the same shell in which you execute the next command. Running source in one shell and installing from a separate SSH command does not carry the changed PATH over. Either activate and install in one session or use absolute paths:

~/projects/myproject/.venv/bin/python -m pip install -r requirements.txt

Creation succeeds but the wrong Python version appears

Inspect the executable you used and the environment’s interpreter:

command -v python3
python3 --version
source .venv/bin/activate
python --version
python -c 'import sys; print(sys.executable)'

If the version is not the one required by the project, remove or rename the environment only after recording its dependencies, then recreate it with the desired executable, such as python3.11 -m venv .venv.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A repeatable setup sequence

For a new Ubuntu or Debian project, this complete sequence keeps each operation visible:

  1. Identify the operating system with cat /etc/os-release.
  2. Check the intended interpreter with python3 --version.
  3. Install the module package using sudo apt update followed by sudo apt install python3-venv, or the matching versioned package when required.
  4. Enter the project directory with cd.
  5. Create the environment using the exact interpreter you want, for example python3 -m venv .venv.
  6. Activate it with source .venv/bin/activate.
  7. Verify command -v python and python -m pip --version point into .venv.
  8. Optionally upgrade pip with python -m pip install --upgrade pip.
  9. Install declared dependencies with python -m pip install -r requirements.txt.
  10. Run project commands using the activated interpreter or its full path.
  11. Run deactivate when the session is finished.

When to recreate or upgrade an environment

Because the environment records the base interpreter in pyvenv.cfg, changing the system Python does not automatically convert an existing environment to a different minor version. If a project must move to another interpreter, create a new target with that interpreter and reinstall the project’s dependencies. Keep the old directory until the new setup has been checked.

The --upgrade flag is intended to update an existing environment’s core files to match the interpreter used for the command. It is different from installing application packages and does not replace the need to manage the project’s requirements.

Practical checks before running the application

  • The environment directory is the one you intended, such as ~/projects/myproject/.venv.
  • python --version reports the project’s required interpreter version.
  • python -m pip --version shows a location under the environment.
  • Dependencies were installed without sudo pip.
  • Any startup script that runs outside an interactive shell calls .venv/bin/python explicitly or activates the environment in the same shell process.
  • You know whether the environment was created with --system-site-packages; that choice changes what the project can import from the VPS.

For version-specific behavior and the complete option list, consult the Python documentation for the interpreter installed on the VPS: docs.python.org/3/library/venv.html.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.