Python Environment Setup

1 0
Read Time:3 Minute, 20 Second

Environment Setup

Python is available on a wide variety of platforms including Linux and Mac OS X. Let’s understand how to set up our Python environment.

Local Environment

Open a terminal window and type “python” to find out if it is already installed and which version is installed.

Downloading Python

You can download Python from https://www.python.org/downloads/.

Installing Python

After download specified version and specified operating system python installer, install python.

Once you’ve successfully run the Python installer, you should see the following icons appear in your start menu, on your home screen:

image

Add the Python 3.10 Directory to your System Path Environment Variable

In order to make it so you can access Python via any command line prompt (and not just the Python-specific one), you’ll need to add the newly-installed Python 3.10 directory to your “Path” system environment variable. This makes it easier to access Python and run scripts in whatever shell you’re using to using (Command Prompt, PowerShell, and Git Bash.)

So, go to Control Panel –> System Properties –> Environment Variables and select the PATH variable from the list below:

image

Click Edit

image

With that in place, you can now start the Python interpreter on any command prompt by invoking the python command. Let’s get our package manager set up for Python.

Install pip to Manage Your Python Packages

Step-1 Download PIP get-pip.py

Before installing PIP, download the – get-pip.py file for 3.x and get-pip.py file for 2.7

  1. Launch a command prompt if it isn’t already open. To do so, open the Windows search bar, type cmd and click on the icon.
  2. Then, run the following command to download the get-pip.py file:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

Step-2 Installing PIP on Windows

To install PIP type in the following:

python get-pip.py

Upgrading PIP for Python on Windows

To upgrade PIP on Windows, enter the following in the command prompt:

python -m pip install --upgrade pip

This command uninstalls the old version of PIP and then installs the most current version of PIP.

Downgrade PIP Version

Downgrading may be necessary if a new version of PIP starts performing undesirably. To downgrade PIP to a prior version, specifying the version you want.

To downgrade PIP, use the syntax:

python -m pip install pip==version_number

For example, to downgrade to version 18.1, you would run:

python -m pip install pip==18.1

You should now see the version of PIP that you specified.

Install virtualenv to Create Local Python Environments for Your Projects

Once you have pip installed, you need to grab one last package – virtualenv.

Packages in Python are installed globally by default – which means that when a package dependency changes for one project running in a given Python environment, it changes for all of them. Not good!

virtualenv restores order to the universe by allowing you to create virtual Python environments, so you don’t have to worry about version conflicts between projects.

And now that you have pip up and running on your system, it’s trivial to install virtualenv via the command line:

C:\> pip install virtualenv

And you’re done!

Bonus – Install scaffold-py to Easily Create New Python Projects

To install and use scaffold-py run this command:

C:\> pip install scaffold

C:\> python –m scaffold –p “NewProjectName”

Each project you scaffold will create the following directory structure:

/[projectname]/
/[projectname]/setup.py
/[projectname]/bin
/[projectname]/docs
/[projectname]/[projectname]
/[projectname]/[projectname]/__init__.py
/[projectname]/tests
/[projectname]/tests/__init__.py
/[projectname]/tests/[projectname]_tests.py

Both setup.py and [projectname]_tests.py are set up automatically to reference your project name as a module. The rest is up to you!

Thanks for reading see you in next topic.

Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
100 %

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Comment