Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
January 23, 2022 01:58 am GMT

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.

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 projects 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


Original Link: https://dev.to/elechipro/create-a-virtual-environment-for-python-projects-284d

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To