Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install venv with pip on linux ubuntu 18.04 python 3.7

I tried to install venv with pip, and it gave me the following error message:

this is the command:

$ pip install venv

and the error:

Collecting venv
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 353, in run
    wb.build(autobuilding=True)
  File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 749, in build
    self.requirement_set.prepare_files(self.finder)
  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 554, in _prepare_file
    require_hashes
  File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 278, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 465, in find_requirement
    all_candidates = self.find_all_candidates(req.name)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 423, in find_all_candidates
    for page in self._get_pages(url_locations, project_name):
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 568, in _get_pages
    page = self._get_page(location)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 683, in _get_page
    return HTMLPage.get_page(link, session=self.session)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 795, in get_page
    resp.raise_for_status()
  File "/usr/share/python-wheels/requests-2.18.4-py2.py3-none-any.whl/requests/models.py", line 935, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
HTTPError: 404 Client Error: Not Found for url: https://pypi.org/simple/venv/

os: linux ubuntu 18.04 python 3.7

Thank you!

like image 367
roye1233 Avatar asked Nov 03 '19 18:11

roye1233


Video Answer


1 Answers

On Ubuntu 18.04, python executable is bound by default to python2.7 (Which is now EOL); so when you do:

pip install venv

You're trying to install venv on Python2.7 which is only compatible with python3.3+ (see below) and that's why you get those errors.

As a side note, you don't need to install venv on python3.3+ because it's included by default, see venv documentation, but the distribution maintainers may ship Python without this module, so you'll have to install it using your package manager, in this case:

sudo apt install python3-venv -y 

Creation of virtual environments is done by executing the command:

python3 -m venv /path/to/new/virtual/environment

For previous versions of Python (in your case 2.7), you can use virtualenv

pip install virtualenv

And the creation:

virtualenv -p /usr/bin/python2.7 <path/to/new/virtualenv/>

Note that the -p flag is not mandatory, it's just to make sure you're calling the correct Python version in case you installed virtualenv with both Python 2 and Python 3.

like image 73
RMPR Avatar answered Sep 19 '22 23:09

RMPR