Create a virtual environment for Python Projects

Hello there, in this short note I’ll show you how to create a python virtual environment for a new project and walk you through the process of resolving some common conflicts you might get while creating a virtual environment for your projects.


This content originally appeared on DEV Community and was authored by Elechi George

Hello there, in this short note I'll show you how to create a python virtual environment for a new project and walk you through the process of resolving some common conflicts you might get while creating a virtual environment for your projects.

First things first, you will need to make sure python and pip are installed properly

to check this just run the stuff below in your favourite terminal

  $ python --version

if you an error like the one below, it probably because you don't have python correctly installed or you it haven't be added to your system environment variables path

Image showing how to setup environment variable on windows

Here's how to add it yourself

type "edit system environment variable" - follow the images below to get it resolved

Once you type that stuff from before, it should land you here, look to the bottom where it says environment variable CLICK IT !

Image showing how to setup environment variable on windows

That button should land you here, DOUBLE CLICK where that blue color stuff is on [path] just like the image below

Image showing how to setup environment variable on windows

That double clicking should land you here, make sure yours is like mine in the picture below [especially the first two]

Image showing how to setup environment variable on windows

Okay great, once you finish editing "click save" and go back to this area, and DOUBLE CLICK where my cursor is on the image below that has a blue background

Image showing how to setup environment variable on windows

It should land you here, make sure yours looks like mine, especially the last two variables

Image showing how to setup environment variable on windows

when you are done, click save until the boxes disappear, you shouldn't be having error with python and pipenv

MOVING FARWARD and Installing Pipenv

Pipenv manages dependencies on a per-project basis. To install packages, change into your project’s directory (or just an empty directory) and run:

  $ cd code_folder

  $ pip install pipenv --user 

  $ pipenv install requests

it does it what it does in creating a virtual environment for your project and out out some that looks like the image below...

Image success on creating a virtual environment

You should be all set, if you want to use virtualenv instead of pipenv - all you need to do is run the commands below:

  $ pip install virtualenv --user

then to use it, run:

  $ cd project_folder
  $ virtualenv venv

to activate it run:

  $ source venv/bin/activate

In summary to setup a virtual environment

  • install python

  • install pipenv

  • change the environment variables to point accordingly

  • then run pipenv install requests on the folder you want to create your python project

CHEERS, If you have questions, let me know in the comments

Thanks


This content originally appeared on DEV Community and was authored by Elechi George


Print Share Comment Cite Upload Translate Updates
APA

Elechi George | Sciencx (2022-01-23T01:58:58+00:00) Create a virtual environment for Python Projects. Retrieved from https://www.scien.cx/2022/01/23/create-a-virtual-environment-for-python-projects/

MLA
" » Create a virtual environment for Python Projects." Elechi George | Sciencx - Sunday January 23, 2022, https://www.scien.cx/2022/01/23/create-a-virtual-environment-for-python-projects/
HARVARD
Elechi George | Sciencx Sunday January 23, 2022 » Create a virtual environment for Python Projects., viewed ,<https://www.scien.cx/2022/01/23/create-a-virtual-environment-for-python-projects/>
VANCOUVER
Elechi George | Sciencx - » Create a virtual environment for Python Projects. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/01/23/create-a-virtual-environment-for-python-projects/
CHICAGO
" » Create a virtual environment for Python Projects." Elechi George | Sciencx - Accessed . https://www.scien.cx/2022/01/23/create-a-virtual-environment-for-python-projects/
IEEE
" » Create a virtual environment for Python Projects." Elechi George | Sciencx [Online]. Available: https://www.scien.cx/2022/01/23/create-a-virtual-environment-for-python-projects/. [Accessed: ]
rf:citation
» Create a virtual environment for Python Projects | Elechi George | Sciencx | https://www.scien.cx/2022/01/23/create-a-virtual-environment-for-python-projects/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.