Error in installing venv for python3 on mac - python

While installing a virtual environment by running the following command on terminal:
python3 -m pip install --user venv
I'm encountering the following error:
ERROR: Could not find a version that satisfies the requirement venv
ERROR: No matching distribution found for venv
Please help me with this! I believe since default python is version 2.x in macOS I must try installing virtualenv but I require venv.

You cannot install venv with pip: venv is a module from the standard library since Python 3.3. So you don't need to install it, just start using:
python3 -m venv path/to/new-venv

Venv doesn't exists. I guess that you might want the package virtualenv.
Venv is commonly used as the name of virtual environment created by virtualenv.
So, the command is:
python3 -m pip install --user virtualenv
python3 -m virtualenv venv

Related

Mac M1 python packages error after upgrade to python3

I am writing a project in NativeScript and I received the following error the last few days when I tried the commands: ns run ios or ns doctor.
Couldn't retrieve installed python packages.
The Python 'six' package not found.
I tried python and pip upgrade and also the command pip install six.
Nothing of them fixed the problem.
I believe that is not a NativeScript issue, is about the configuration of the python packages in my machine. I mention that I am using a MacBook with M1 chip and it is running the 12.5 OS version.
I will appreciate any suggestions on this situation.
Lastly, I found the solution. It was about the python folder into the path /usr/local/bin/python
You could check it by the following command: where python
In my case this folder is missing, perhaps I deleted it after the upgrade of the python3.
That was a mistake both folders should exist on this path!
If you type: where python you should receive: /usr/local/bin/python
If you type: where python3 you should receive: /usr/local/bin/python3
In order to fix the error, I installed python again by using the brew install pyenv
this suggestion helps me to install it properly.
In the end, in order to eliminate all errors I installed the Python six package by using the command:
pip install --ignore-installed six
Try doing it with the python virtual environment. Following are the steps.
Create a virtual environment.
Activate the virtual environment.
Run the pip install command with the virtual environment active.
Implement as follows:
use correct version of Python when creating VENV
python3 -m venv venv
activate on Unix or MacOS
source venv/bin/activate
activate on Windows (cmd.exe)
venv\Scripts\activate.bat
activate on Windows (PowerShell)
'venv\Scripts\Activate.ps1'
install the required package in the virtual environment
python3 -m pip install --upgrade pip
python3 -m pip install six
Note: This works only when you are in the virtual environment.

Command "python3 -m pip install [...]" failed with error code 1 in None

I am trying to install the PyInstaller module for python through the terminal on my mac, and it is not working.
I am trying to install this module so I can package a program. I have tried to install through terminal through different commands (e.g. "pip install pyinstaller), but it is not working, even though I know I have PIP correctly installed.
When trying to install, I type, python3 -m pip install pyinstaller.
The result is Command "/usr/local/bin/python3 -m pip install --ignore-installed --no-user --prefix /private/var/folders/w5/rlzrygt57j3c3nl4p29d2djc0000gw/T/pip-build-env-mjrd7sir https://files.pythonhosted.org/packages/b2/86/095d2f7829badc207c893dd4ac767e871f6cd547145df797ea26baea4e2e/setuptools-41.2.0-py2.py3-none-any.whl#sha256=4380abcf2a4ffd1a5ba22d687c6d690dce83b2b51c70e9c6d09f7e8c7e8040dc https://files.pythonhosted.org/packages/00/83/b4a77d044e78ad1a45610eb88f745be2fd2c6d658f9798a15e384b7d57c9/wheel-0.33.6-py2.py3-none-any.whl#sha256=f4da1763d3becf2e2cd92a14a7c920f0f00eca30fdde9ea992c836685b9faf28" failed with error code 1 in None
I have upgraded PIP, and tried using sudo python3 -m pip install pyinstaller, but I am not in the sudoers file.
Please help
Create a virtual environment for your project in your project directory.
python3 -m venv env
source env/bin/activate
Test which python is activated
which python
This will show that your local python in the virtualenv you just created is now the current python
Try installing now using
pip install pyinstaller
This ought to work for you. Always use virtual environments for your projects instead of installing system wide libraries unless you really need to set this up for the system.

Can not find the virtualenv command after pip3 installed

I use the pip3 install the virtualenv in my CentOS7.2:
[root#www abc]# pip3 install virtualenv
Requirement already satisfied: virtualenv in /usr/local/Python3/lib/python3.5/site-packages (15.1.0)
[root#www abc]# virtualenv --no-site-packages venv
-bash: virtualenv: do not find the command
But I can not use it, there do not find the command.
Instead of using virtualenv, try running python3 -m venv. So to create a new virtualenv, just do python3 -m venv ~/.virtualenvs/my_virtualenv.
As for why you can't find virtualenv by just typing it in, I guess that it's because virtualenv.py script is somewhere in /usr/local/Python3/lib/python3.5/site-packages - probably at /usr/local/Python3/lib/python3.5/site-packages/virtualenv.py - try running it directly.
pip is just a Python packaging utility. It's not responsible for adding tools into your PATH environment variable, or for installing utilities in your system.
If you want virtualenv command to be present in your system, I would recommend to install it using your system package manager instead. I would recommend to just use the built-in venv module instead.

How to set python version for pip in virtualenv?

Need to run some project that require installing packages available only for Python 2.7 (I can't change packages). I'm running Ubuntu 17.04 with Python 3.5.3 . I created virtual environment by issuing next command:
sudo virtualenv --python=/usr/bin/python2.7 env
Seems like I have version I need:
(env) serv#serv:/var/m$ python -V
Python 2.7.13
But when I'm trying to install packages(those only for Python 2.7) it DOESN'T look like my virtualenv is using python 2.7 what is more interested, it refers to already installed packages(I supposed that virtualenv won't have any packages,except for some default as pip).
Installing mysql-python (this usually error occurs only when installing from python 3):
ImportError: No module named 'ConfigParser'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-fi75i_pl/mysql-python/
When I'm installing package for Python3 - SQLAlchemy:
Requirement already satisfied: SQLAlchemy in /home/loraserver/.local/lib/python3.5/site-packages
What can I do to run my code from Python 2.7 environment?
EDIT 1: I'm installing mysql-python by:
pip install mysql-python
This gives me Permission denied.
When I'm trying :
sudo pip install mysql-python
It gives me error the same from installing python on python3.
I think the issue is that you created your virtual environment using sudo.
This may require you to use sudo whenever working inside of your environment, causing your packages to be installed globally.
Try creating a new virtual environment without using sudo and then installing your packages from there.
Run the following commands to test it:
virtualenv --python=/usr/bin/python2.7 testenv
source testenv/bin/activate
pip install mysql-python
Do sudo rm -rf env and then (without using sudo) start over:
$ virtualenv venv
$ source venv/bin/activate
Verify that which python shows a python within your project, and similarly for which pip. Then:
$ pip install mysql-python
BTW, there is a nice program named /usr/bin/env, so it is usual to name your directory "venv" rather than "env".

Pip installation in virtualenv broken

I get this error from the virtualenv's pip installation:
➜ myproject git:(master) ✗ pyenv/bin/pip --help
Failed checking if argv[0] is an import path entry
ValueError: character U+6e657970 is not in range [U+0000; U+10ffff]
Fatal Python error: no mem for sys.argv
ValueError: character U+6e657970 is not in range [U+0000; U+10ffff]
Current thread 0x00007fff767c5000 (most recent call first):
[1] 10941 abort pyenv/bin/pip --help
The virtual env's python works, the system python and pip work (all python3).
Turns out that virtualenv hard links the python executable to the system python, so that when I upgraded python, it got out of line with the virtual env's pip installation.
Posting here for other to find, in case this happens to them.
Solution is to wipe the pyenv folder, and reinstall a fresh virtualenv (if you've been using a requirements.txt file, this is what the virtual env is designed to do!
According to the pip documentation, you can install pip in a virtual environment by typing the following command when your virtual environment is activated:
python -m ensurepip --upgrade
For your information, ensurepip is an in-built Python module that serves the purpose of installing pip in your Python environment.
This solution can be used if you do not want to start a fresh new virtual environment and you want to retain your dependencies
First, try updating pip
pip install --upgrade pip
if this does not fix it, I would try uninstalling pip and then reinstall.
to remove try:
sudo pip uninstall pip
then install again.
pip install -U pip setuptools
also i am assuming your are using linux or mac. on windows commands differ.

Categories