Featured

TechBytes on Linux

This is a growing list of Linux commands which might come handy for the of Linux users. 1. Found out i had to set the date like this: ...

Monday, July 20, 2020

Installing pip with get-pip.py in a Python virtual environment on Windows MacOS & Linux

  • To create a Python virtual environment type below commands on the required console prompt:

On Windows
    python -m venv ./venv
    .\venv\Scripts\activate
On Ubuntu
    python3 -m venv ./venv
     source ./venv/bin/activate    
There are some exceptional cases where vent creation might fail. Here are some workarounds -
https://askubuntu.com/questions/1268833/error-command-path-to-env-bin-python3-7-im-ensurepip-upgrade
123

To exit a Python virtual environment, you can use the deactivate command. This command is available in most Unix-like systems and Windows.

Example

$ deactivate

Steps to Exit Virtual Environment

1. Using deactivate Command

The most common way to exit a virtual environment is by using the deactivate command1.

Example:

$ deactivate

2. Using source deactivate

In some cases, especially with certain virtual environment management tools like virtualenvwrapper, you might need to use the source deactivate command2.

Example:

source deactivate

  • To install pip, securely download get-pip.py by following this link: get-pip.py. Alternatively, use curl:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

Then run the following command in the folder where you have downloaded get-pip.py:

python get-pip.py

Warning

 

Be cautious if you are using a Python install that is managed by your operating system or another p

ackage manager. get-pip.py does not coordinate with those tools, and may leave your system in an inconsistent state. Hence it is recommended to use venv (Python Virtual Environment) to isolate the working environment with the Python environment at the system level.
Found this article to be a gem to troubleshoot pip errors on Windows -- https://jhooq.com/pip-install-connection-error/

To install python3 & virtualenv on MacOS

Python3 Virtualenv Setup

Requirements:

  • Python3
  • Pip3
$ brew install python3 #upgrade

Pip3 is installed with Python3

Installation

To install virtualenv via pip run:

$ pip3 install virtualenv

Usage

Creation of virtualenv:

$ virtualenv -p python3 <desired-path>

Activate the virtualenv:

$ source <desired-path>/bin/activate

Deactivate the virtualenv:

$ deactivate

You can see more about the Homebrew on the official page.


No comments:

Post a Comment

Popular Posts