Skip to content

Spirit Yatra

  • Home
  • Entertainment
  • Finance
  • School
  • Journey
  • Product
  • Crypto-Currency

Beginner Python – Creating Virtual Environment

July 1, 2020 by Stilgar

For every project that I am working on, I create a virtual environment for it so that whatever libraries I have installed are distinct and separate from other project and system libraries.

Beginner Python – Creating Virtual Environment

  • Folder for Projects
    • Have a folder where you create all the projects you are working on
      • Create a folder called Projects to have all of your project in one place
  • Create a directory for Creating Virtual Environments
    • Within the Projects folder, create a folder of your new project i.e. a car deals project has a folder called “autoprice”.
    • Open up your terminal
    • Change Directory (cd) and go within the project folder i.e. “autoprice”
    • Input the following commands (You need to have virtualenv installed already)
    • virtualenv nameofenv_env (i.e. virtualenv autoprice_env)
      • This will install setup tools, and pip
      • I just use _env as a self-reference that the folder is a virtual environment folder
    • Important to note, do not mix-up folder of projects with folder of virtual environment. Virtual Environments are merely a way for you to separate out packages and dependencies projects to projects.
    • Environments are not for your project files.
    • Creating an Environment with a Specific Version of Python (2.6 for example)
      • virtualenv -p /usr/local/bin/python2.6 env_name
  • Activating the newly created Environment
    • source nameofenv_env/bin/activate
    • You should now be in your new environment
  • Validating Which Environment You are In
    • which python
    • You should see the source be in the newly created environment directory
    • which pip
      • You should see the source be in the newly created environment directory
    • pip list
      • Only displays setup tools of the newly created virtualenv and non of the system tools
  • Installing additional packages in the newly created Python Environment
    • pip install lumpy
    • pip install pytz
    • pip install psutil
    • You should the above packages in the newly created environment
  • Exporting Packages and Their Version Numbers to another Environment / Project
    • pip freeze –local > requirements.txt
    • cat requirements.txt
    • Go to the environment where you want to install all these packages
    • pip install -r requirements.txt
  • Exit Python Virtual Environment
    • deactivate
  • Delete Python Environment
    • Deactivate Python Environment first
    • rm -rf nameofenv_env

Read Learn to Code in Python to see how I got started with Python development

Post navigation

Previous Post:

How to Use Lists in Python Notes

Next Post:

Watched Old Guard Movie on Netflix with Charlize Theron

Leave a Reply Cancel reply

You must be logged in to post a comment.

Recent Posts

  • My Recent Experience With Trading 0-Day Options February 21, 2025
  • Leveraging AI Tools to Start Working on New Projects February 18, 2025
  • How I Went Through a Javascript 1-Hr Tutorial on Youtube July 12, 2020
  • How to do File Import in Python Notes July 11, 2020
  • Will Learn Javascript Starting This Week July 11, 2020

About Spirit Yatra

This site chronicles my life journey – my challenges, joys, daily mundane activities and observations.

© 2025 Spirit Yatra | Built using WordPress and SuperbThemes