How to install and run virtualenv on MacOS correctly

2024/7/2 14:56:47

Hi I'm a beginner of python, I don't remember when and how I installed python3.8 on my Macbook air, only knew the installed path:

% which python
/usr/bin/python
% which python3
/usr/local/bin/python3

The pip command cannot not be found but pip3 is ok. Today I want to install virtaulenv:

% sudo -H pip3 install virtualenv
WARNING: Ignoring invalid distribution - (/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages)
Successfully installed virtualenv-20.6.0

I can use "pip3 show virtualenv" to know the info:

% pip3 show virtualenv
Name: virtualenv
Version: 20.6.0
Summary: Virtual Python Environment builder
Home-page: https://virtualenv.pypa.io/
Author: Bernat Gabor
Author-email: [email protected]
License: MIT
Location: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages
Requires: six, platformdirs, backports.entry-points-selectable, distlib, filelock
Required-by:

But when I use "virtualenv" I got command not found message then I "pip3 uninstall" it. I searched for this and got a tip to use "easy_install" to install virtualenv. After installed I can execute the command, but got some error message:

% virtualenv                     
Traceback (most recent call last):File "/usr/local/bin/virtualenv", line 6, in <module>from pkg_resources import load_entry_pointFile "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3241, in <module>@_call_asideFile "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3225, in _call_asidef(*args, **kwargs)File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 3254, in _initialize_master_working_setworking_set = WorkingSet._build_master()File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 583, in _build_masterws.require(__requires__)File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 900, in requireneeded = self.resolve(parse_requirements(requirements))File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources/__init__.py", line 786, in resolveraise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'importlib-resources>=1.0' distribution was not found and is required by virtualenv

It seems doesn't work and I try the "sudo pip3 uninstall virtualenv" to uninstall it successfully, but it seems not really be removed:

% which virtualenv              
/usr/local/bin/virtualenv

I have no idea about this, could you help me? I just want to run virtualenv normally and create flask project ...

PS. I can "sudo pip3 install flask" and "pip3 show flask" but still cannot run flask cammand (command not found), what should I do?

Thanks a lot!

Answer

try being explicit in the version of python you are using and install using -m pip instead

python3 -m pip install virtualenv
python3 -m virtualenv venv # create a new venv in ./venv
source ./venv/bin/activate # activate your new venv

often times the pip/pip3 just isnt pointing at the same python version you think you are using... by using this technique you are sure to be using the correct python and pip

https://en.xdnf.cn/q/73367.html

Related Q&A

comparing a string 1-d numpy array elementwise

I have two 1-d arrays (a and b) containing strings, which I want to compare element wise to get output c like shown below. I tried converting it to set and comparing, however that does not give the cor…

Can Atom work with Python virtualenvwrapper

I want to start a Flask app. I installed virtualenvwrapper to manage the packages but I cant let Atom know that the current project should use the virtualenvs python binary.from flask import Flask, ren…

Concatenation of tuples

Normal text:Im having some problems with coding on python 3.2.1. Actually Im taking online lectures that are on python 2.5.Here is the code:x = 100 divisors = () for i in range(1,x):if x%i == 0:divisor…

How do I create a new data table in Orange?

I am using Orange (in Python) for some data mining tasks. More specifically, for clustering. Although I have gone through the tutorial and read most of the documentation, I still have a problem. All th…

How to turn off MySQL query cache while using SQLAlchemy?

I am working with a fairly large MySQL database via the SQLAlchemy library, and Id love to turn off MySQLs query caching to debug performance issues on a per-session basis. Its difficult to debug slow …

Storing an inverted index

I am working on a project on Info Retrieval. I have made a Full Inverted Index using Hadoop/Python. Hadoop outputs the index as (word,documentlist) pairs which are written on the file. For a quick acc…

How to determine whether java is installed on a system through python?

Using Python, I want to know whether Java is installed.

How should I save the model of PyTorch if I want it loadable by OpenCV dnn module

I train a simple classification model by PyTorch and load it by opencv3.3, but it throw exception and sayOpenCV Error: The function/feature is not implemented (Unsupported Lua type) in readObject, file…

Apache Spark ALS - how to perform Live Recommendations / fold-in anonym user

I am using Apache Spark (Pyspark API for Python) ALS MLLIB to develop a service that performs live recommendations for anonym users (users not in the training set) in my site. In my usecase I train th…

python JIRA connection with proxy

Im trying to connect via python-jira using a proxy:server = {"server": "https://ip:port/jira",proxies: {"http": "http://ip:port", "https": "http:/…