Using virtualenv and pip
Learn how to create isolated Python environments and manage Python packages using virtualenv and pip.

These programs allow you to ensure that your Python applications have the exact environment and dependencies they need, without interfering with system-wide Python installations.


 Important

  • On shared, reseller, and Turbo hosting accounts, use the Python Selector to manage Python environments.

  • Managed VPS and Dedicated servers activated in May 2023 or later should also use the Python Selector.

  • For managed VPS/Dedicated servers activated before May 2023, follow the steps below.


Creating and activating a Python environment with virtualenv

  1. Log in via SSH.

  2. Ensure you are in your home directory:

cd ~
  1. Create a new environment (replace project with your desired name):

virtualenv project
  • By default, virtualenv uses the system Python version (commonly 2.7).

  • To use a specific Python version, such as Python 3:

virtualenv -p python3 project
  1. Activate the environment:

source project/bin/activate
  • When active, your prompt shows (project) at the beginning.

  1. To exit the environment, type:

deactivate

Using pip to manage Python packages

pip is installed automatically when you create a virtual environment with virtualenv.

  1. Activate the environment (if not already active):

source ~/project/bin/activate
  1. Search for a package:

pip search pkgname
  • Example: Search for MySQL-related packages:

pip search mysql
  1. Install a package:

pip install pkgname
  1. Uninstall a package:

pip uninstall pkgname

More information

هل كانت المقالة مفيدة ؟ 0 أعضاء وجدوا هذه المقالة مفيدة (0 التصويتات)

Powered by WHMCompleteSolution