How to use virtualenv with python3.6 on ubuntu 16.04?

2024/11/19 17:28:42

I'm using Ubuntu 16.04, which comes with Python 2.7 and Python 3.5. I've installed Python 3.6 on it and symlink python3 to python3.6 through alias python3=python3.6.

Then, I've installed virtualenv using sudo -H pip3 install virtualenv. When I checked, the virtualenv got installed in "/usr/local/lib/python3.5/dist-packages" location, so when I'm trying to create virtualenv using python3 -m venv ./venv1 it's throwing me errors:

Error Command: ['/home/wgetdj/WorkPlace/Programming/Python/myvenv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']

What should I do?

Answer

We usually use $ python3 -m venv myvenv to create a new virtualenv (Here myvenv is the name of our virtualenv).

Similar to my case, if you have both python3.5 as well as python3.6 on your system, then you might get some errors.

NOTE: On some versions of Debian/Ubuntu you may receive the following error:

 The virtual environment was not created successfully because ensure pip is not available.  On Debian/Ubuntu systems, you need to install the python3-venv package using the following command.apt-get installpython3-venv  You may need to use sudo with that command.  After installing the python3-venv package, recreate your virtual environment. 

In this case, follow the instructions above and install the python3-venv package:

$ sudo apt-get install python3-venv

NOTE: On some versions of Debian/Ubuntu initiating the virtual environment like this currently gives the following error:

Error Command: ['/home/wgetdj/WorkPlace/Programming/Python/myvenv/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']

To get around this, use the virtualenv command instead.

$ sudo apt-get install python-virtualenv
$ virtualenv --python=python3.6 myvenv

NOTE: If you get an error like

E: Unable to locate package python3-venv

then instead run:

sudo apt install python3.6-venv
https://en.xdnf.cn/q/26411.html

Related Q&A

Is a day always 86,400 epoch seconds long?

While reviewing my past answers, I noticed Id proposed code such as this:import timedef dates_between(start, end):# muck around between the 9k+ time representation systems in Python# now start and end …

Find the first instance of a nonzero number in a list in Python [duplicate]

This question already has answers here:Return the index of the first element of a list which makes a passed function true(7 answers)Closed last year.I have a list like this: myList = [0.0, 0.0, 0.0, 2.…

How to debug a Python module in Visual Studio Codes launch.json

My question may seem simple but, I have a module that I launch in a terminal like this: python -m my_module.my_fileHow do I debug this in Visual Studio Code? I have this in my launch.json (documentati…

Cleanest Fastest server setup for Django [closed]

Closed. This question is opinion-based. It is not currently accepting answers.Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.Clo…

Quicker to os.walk or glob?

Im messing around with file lookups in python on a large hard disk. Ive been looking at os.walk and glob. I usually use os.walk as I find it much neater and seems to be quicker (for usual size direct…

Getting PyCharm to recognize python on the windows linux subsystem (bash on windows)

While running Linux versions of python, pip etc. "natively" on windows is amazing, Id like to do so using a proper IDE. Since SSHD compatibility has not been implemented yet, Im trying get Py…

Whats the difference between nan, NaN and NAN

In numpy there are nan, NaN and NAN. Whats the sense of having all three, do they differ or any of these can be used interchangeably?

Python requests: URL base in Session

When using a Session, it seems you need to provide the full URL each time, e.g.session = requests.Session() session.get(http://myserver/getstuff) session.get(http://myserver/getstuff2)This gets a littl…

size of NumPy array

Is there an equivalent to the MATLAB size() command in Numpy? In MATLAB, >>> a = zeros(2,5)0 0 0 0 00 0 0 0 0 >>> size(a)2 5In Python, >>> a = zeros((2,5)) >>> a ar…

Feature Importance Chart in neural network using Keras in Python

I am using python(3.6) anaconda (64 bit) spyder (3.1.2). I already set a neural network model using keras (2.0.6) for a regression problem(one response, 10 variables). I was wondering how can I generat…