Unable to create virtual environment on CentOS 7.8 and python3.6 - virtualenv

I have two servers that are running CentOS 7.8 with all the latest patches as of the date of this post. On one server I can create a venv, and on the other I get an error. Here is the command used to create the venv:
python3.6 -m venv venv
The error is:
Error: Command '['/root/venv/bin/python3.6', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
So it seems there is a problem after the venv is created. In fact, it makes the links to the python interpreters in venv/bin, but the lib64/python3.6 and lib/python3.6 directories that are created have only empty site-packages in them. I get the problem whether running the command with root privileges (as above) or as a non-privileged user. On the other system, which is not quite the same hardware but very similar, I get no errors.
I have tried a bunch of things including completely uninstalling all the python3 rpms and reinstalling them on both systems. The python3 modules installed are:
python3, python3-devel, python3-libs, python3-other-rpm-macros, python3-pip, python3-rpm-generators, python3-setuptools, python3-tkinter, python3-wheel. All these are installed using the centos repos.
I have searched the internet and one thing that works is to use --no-pip. However, not surprisingly, if I do that I get a venv with no pip, which does not work very well. The version of pip that is installed with the rpm is version 9.0.3. However, I have tried upgrading pip:
python3.6 -m pip install --upgrade pip
This installs pip 20.1. Interestingly, it is installed in /usr/local/lib/python/site-packages. In any event, it doesn't change anything and I get essentially the same error message.
I have even gone as far as rsyncing the /usr/lib/python3.6 and /usr/lib64/python3.6 (using -avu --delete) on the two servers so that they are identical. All to no avail. I am at a loss to know what to do.
I can of course hack things to make them work, but since I am using this to automatically build test environments I really need to get it working automatically. Suggestions would be greatly appreciated.

I've had the same issue on CentOS Linux release 7.9.2009 (Core) and solved it by installing the following system packages:
yum install python36-devel
yum install python36-setuptools
yum install python36-virtualenv
python3.6 -m pip install --upgrade pip
Used virtualenv to install the venv into the project-root:
python3 -m virtualenv venv-dev
After sourcing the venv everything looks good and I could install the needed requirements:
. ./venv-dev/bin/activate
python3 --version
Python 3.6.8
pip3 --version
pip 21.1.1 from /project/root/dir/venv-dev/lib/python3.6/site-packages/pip (python 3.6)
pip3 install -r requirements/dev.txt
Successfully installed ...

Related

How to install egg file with easy_install?

On a HPC node, I have a file named pysdf-0.1-py3.8-linux-x86_64.egg.
I found a Nvidia Manual to install this file using python -m easy_install pysdf-0.1-py3.8-linux-x86_64.egg.
However, when I run this command I get the following error.
(/scratch/s.1915438/modulus) [s.1915438#sl1 eggs]$ python -m easy_install pysdf-0.1-py3.8-linux-x86_64.egg
/scratch/s.1915438/modulus/bin/python: No module named easy_install
Similarly, if I use pip install as follows
(/scratch/s.1915438/modulus) [s.1915438#sl1 eggs]$ python -m pip install pysdf-0.1-py3.8-linux-x86_64.egg
ERROR: Could not find a version that satisfies the requirement pysdf-0.1-py3.8-linux-x86_64.egg (from versions: none)
ERROR: No matching distribution found for pysdf-0.1-py3.8-linux-x86_64.egg
I do not have admin access on HPC server to use sudo apt. My python is installed at /scratch/s.1915438/modulus/bin/python on the HPC machine.
Does anyone knows why it says Could not find a version that satisfies the requirement.
After 3 months, I figured out how to do this. So, egg files can be installed using something called easy_install which was depreciated back in 2019. The last version of setuptools that supported easy_install was setuptools 42.0.0..
So, you need to downgrade to that version as follows.
pip3 install setuptools==42.0.0
And then install the egg files using the following command.
python3 -m easy_install example.egg
If you wish to upgrade the setuptools to the latest version, then type
pip3 install setuptools --upgrade

python2.7 in Raspbian Lite

I have installed Raspbian Lite OS in Raspberry Pi zero.
I found that Raspbian Lite comes with Python3 as default.
But I am gonna run some scripts that uses libraries that are Python2 Compatible.
So I tried to change the default Python version from Python3 to Python2 (Specifically Python2.7.18)
After so much searching and trying, instructions from [this page][1] made my job
Now if I try to check in command writing
python --version
It shows me that it is Python2.7.18
But the problem is I am not being able to install any packages using
sudo apt-get install <python-packagename>
It shows me Errors like
1.Package "python-pip" has no installation candidate (When I tried to install pip)
2. Package python-numpy has no installation candidate (when I tried to install numpy)
3. unable to locate package python-pyaudio (when I tried to install pyaudio)
I am searching but no solution.
Can anyone please help? I am frozen in a critical stage of my project .
Generally, for new raspbian/raspios os with python 3 by default, it is not suggested to replace the system python interpreter to python 2, it may break some system component's dependency.
Instead, you can create a python 2 virtual env, if you need to run python2 scripts.
sudo apt-get install python3-pip
pip install virtualenv
virtualenv -p /usr/bin/python2.7 venv
source venv/bin/activate
You can test the python version as following,
(venv) $ python --version

How to install TensorFlow on Python 3.7

How to install TensorFlow on Python 3.7
Trying:
D:\Users\Downloads>pip install tensorflow
ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
ERROR: No matching distribution found for tensorflow
Windows 10 OS
And with vent error, too
(venv) C:\Users\KvaksManYT>pip install --upgrade tensorflow
ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none)
ERROR: No matching distribution found for tensorflow
I would recommend using a virtual environment using pip install vitualenv. Then, depending on your OS, you want to create and activate an environment.
python3 -m venv /path/to/new/virtual/environment
Then, activate this environment using,
source ./venv/bin/activate
Now, you can install any Python packages you want.
pip install tensorflow==2.0.0
you can install Tensorflow follow those steps
Ubuntu/Linux /mac os /windows
virtualenv does not require a mention pip version
for system install, you need to mention pip version
upgrade pip version
pip install --upgrade pip
#virtualenv install
pip install --upgrade tensorflow
#system install
pip3 install --user --upgrade tensorflow
reference https://www.tensorflow.org/install/pip
I had the same problem with Windows 10 x64, and it was caused because I was using the wrong Python version, both globally and in the venv. I found questions on the issue multiple times on the internet, including yours.
Be sure to use Python versions 3.5-3.8, as per requirements, but also x64, not x32.
Namely, I ran into this error using both
a venv with 3.9.1 x64 (python --version),
and my globally installed 3.8.2 x32 (python3 --version).
So, I downloaded the x64-version of Python 3.8.6 from here.
Note that the command venv does not allow specifying the python version used in the virtual environment,
as per an answer on this question. So I used virtualenv, which I obviously had to install in my global Python version first.
To specify the Python version used in the venv, I used the command virtualenv, as in:
virtualenv --python="C:\Users\me\AppData\Local\Programs\Python\Python38\python.exe myvenv
where you have to give the path to the newly downloaded Python distribution you want to use, if there are several on your PC (for example, I had Python38-32 and Python39 folders in that directory).
Check Python versions in virtual environment
After I activate my myvenv, created as above, I verify the Python versions as follows:
python3 --version
> Python 3.8.2
python --version
> Python 3.8.6
Then, using the command
import struct
print(struct.calcsize("P") * 8)
Within either python3 or python, shows me whether the version is 32bit or 64bit, as per this answer. The python returns a 64, so that is the one you want to use (not python3).
Finally, within the virtual environment, you can run
pip install --upgrade tensorflow
and it will download and install. (Meanwhile, pip3 install --upgrade tensorflow would still return your error inside and outside the virtual enviroment.)

How can I make a list of installed packages in a certain virtualenv?

You can cd to YOUR_ENV/lib/pythonxx/site-packages/ and have a look, but is there any convenient ways?
pip freeze list all the packages installed including the system environment's.
You can list only packages in the virtualenv by
pip freeze --local
or
pip list --local.
This option works irrespective of whether you have global site packages visible in the virtualenv.
Note that restricting the virtualenv to not use global site packages isn't the answer to the problem, because the question is on how to separate the two lists, not how to constrain our workflow to fit limitations of tools.
Credits to #gvalkov's comment here. Cf. also pip issue 85.
Calling pip command inside a virtualenv should list the packages visible/available in the isolated environment. Make sure to use a recent version of virtualenv that uses option --no-site-packages by default. This way the purpose of using virtualenv is to create a python environment without access to packages installed in system python.
Next, make sure you use pip command provided inside the virtualenv (YOUR_ENV/bin/pip). Or just activate the virtualenv (source YOUR_ENV/bin/activate) as a convenient way to call the proper commands for python interpreter or pip
~/Projects$ virtualenv --version
1.9.1
~/Projects$ virtualenv -p /usr/bin/python2.7 demoenv2.7
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in demoenv2.7/bin/python2.7
Also creating executable in demoenv2.7/bin/python
Installing setuptools............................done.
Installing pip...............done.
~/Projects$ cd demoenv2.7/
~/Projects/demoenv2.7$ bin/pip freeze
wsgiref==0.1.2
~/Projects/demoenv2.7$ bin/pip install commandlineapp
Downloading/unpacking commandlineapp
Downloading CommandLineApp-3.0.7.tar.gz (142kB): 142kB downloaded
Running setup.py egg_info for package commandlineapp
Installing collected packages: commandlineapp
Running setup.py install for commandlineapp
Successfully installed commandlineapp
Cleaning up...
~/Projects/demoenv2.7$ bin/pip freeze
CommandLineApp==3.0.7
wsgiref==0.1.2
What's strange in my answer is that package 'wsgiref' is visible inside the virtualenv. Its from my system python. Currently I do not know why, but maybe it is different on your system.
In Python3
pip list
Empty venv is
Package Version
---------- -------
pip 19.2.3
setuptools 41.2.0
To create a new environment
python3 -m venv your_foldername_here
Activate
cd your_foldername_here
source bin/activate
Deactivate
deactivate
You can also stand in the folder and give the virtual environment a name/folder (python3 -m venv name_of_venv).
Venv is a subset of virtualenv that is shipped with Python after 3.3.
list out the installed packages in the virtualenv
step 1:
workon envname
step 2:
pip freeze
it will display the all installed packages and installed packages and versions
If you're still a bit confused about virtualenv you might not pick up how to combine the great tips from the answers by Ioannis and Sascha. I.e. this is the basic command you need:
/YOUR_ENV/bin/pip freeze --local
That can be easily used elsewhere. E.g. here is a convenient and complete answer, suited for getting all the local packages installed in all the environments you set up via virtualenvwrapper:
cd ${WORKON_HOME:-~/.virtualenvs}
for dir in *; do [ -d $dir ] && $dir/bin/pip freeze --local > /tmp/$dir.fl; done
more /tmp/*.fl
why don't you try pip list
Remember I'm using pip version 19.1 on python version 3.7.3
If you are using pip 19.0.3 and python 3.7.4. Then go for pip list command in your virtualenv. It will show all the installed packages with respective versions.
.venv/bin/pip freeze worked for me in bash.
In my case the flask version was only visible under so I had to go to
C:\Users\\AppData\Local\flask\venv\Scripts>pip freeze --local
Using python3 executable only, from:
Gitbash:
winpty my_venv_dir/bin/python -m pip freeze
Linux:
my_venv_dir/bin/python -m pip freeze

Installing psycopg2 into virtualenv when PostgreSQL is not installed on development system

Is it possible to install psycopg2 into a virtualenv when PostgreSQL isn't installed on my development system—MacBook Pro with OS X 10.6?
When I run pip install psycopg2 from within my virtualenv, I received the error shown below.
I'm trying to connect to a legacy database on a server using Django, and I'd prefer not to install PostgreSQL on my development system if possible.
Why not install PostgreSQL?
I received an error when installing PostgreSQL using homebrew. I have Xcode4—and only Xcode4—installed on my MacBook Pro and am thinking it's related to missing gcc 4.0. However, this is a problem for another StackOverflow question.
Update 8:37 AM on April 12, 2011: I'd still like to know if this is possible without installing PostgreSQL on my MacBook Pro. However, I ran brew update and forced a reinstallation of ossp-uuid with brew install --force ossp-uuid and now brew install postgresql works. With PostgreSQL successfully installed, I was able to pip install psycopg2 from within my virtualenv.
Error from pip install psycopg2
$ pip install psycopg2
Downloading/unpacking psycopg2
Running setup.py egg_info for package psycopg2
Error: pg_config executable not found.
Please add the directory containing pg_config to the PATH
or specify the full executable path with the option:
python setup.py build_ext --pg-config /path/to/pg_config build ...
or with the pg_config option in 'setup.cfg'.
Complete output from command python setup.py egg_info:
running egg_info
writing pip-egg-info/psycopg2.egg-info/PKG-INFO
writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
warning: manifest_maker: standard file '-c' not found
Error: pg_config executable not found.
Please add the directory containing pg_config to the PATH
or specify the full executable path with the option:
python setup.py build_ext --pg-config /path/to/pg_config build ...
or with the pg_config option in 'setup.cfg'.
----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /Users/matthew/.pip/pip.log
Preliminary Research
Below are the articles I read as preliminary research:
Installing psycopg2 to use Django with PostgreSQL on OS X
Installing psycopg2 on OS X
Using psycopg2 with virtualenv on Ubuntu JauntyLucid
Postgres, psycopg2, virtualenv install hints
apt-get install libpq-dev
helped me on debian squeeze
From comments:
apt-get install python-dev-is-python3
psycopg depends on pg_config command, and if you don't have it, you can't install psycopg.
If system installation is a problem to you, why don't you try compiling PostgreSQL and including generated bin files in your $PATH? Like:
export PATH=/path/to/compiled/postgresql/bin:"$PATH"
pip install psycopg2
brew install postgresql
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
pip3 install psycopg2
apt-get install libpq-dev
helped me in debian squeeze too . After that do pip install psycopg2. I faced problem of pg_config not found problem when i was setting up my environment on heroku , now its working fine .
You need to install the python-dev package in order to make use of python extensions such as psycopg2. I don't know how to install packages in mac but I run the following commands to install a python package on my Ubuntu machine.
sudo apt-get install python-dev
Or
sudo apt-get install python3-dev
if you are using Python3.x.
Once the installation is finished run the following command within your virtual environment.
pip install psycopg2
You don't need the complete PostgreSQL installed: you only need the client side libraries.
I solved it in MAC OSX using :
$ wget https://ftp.postgresql.org/pub/source/v9.5.3/postgresql-9.5.3.tar.bz2
$ tar xfv postgresql-9.5.3.tar.bz2
$ cd postgresql-9.5.3
$ ./configure
$ make
$ cd src/bin/pg_config
$ export PATH=`pwd`:"$PATH"
$ pip install psycopg2
Use pip install psycopg2-binary, it worked for me when pip install psycopg2 wasn't working.
Using the method you described in your April 12th update, I was able to install PostgreSQL(+1). Note that I originally was running Python 2.7.1 (32bit) and homebrew threw several errors and warnings regarding using a 32bit version of Python. I have since switched the 64/32 bit version of 2.7.1 and it works like a champ.
Regarding the pyscopg2, I was able to install it into my virtual environment from source by editing setup.cfg. I set pg_config to correct path inside homebrew's Cellar (pg_config=/usr/local/Cellar/postgresql/9.0.4/bin/pg_config). After saving the changes, I ran python setup.py install with zero issues. It's worth noting that I did not set the Mac's default python setting to 32 bit. I used the new 64 bit from start to finish.
After looking over some of the documentation, I think if I added homebrew's postgresql path to the system path I could have used pip to install it.
Reference:
http://favosdream.blogspot.com/2009/09/make-psycopg2-and-readline-work-in-snow.html
Update 6-8-2011:
While porting a project written on OS X to Windows 7, I found out that I had to install PostgreSQL on Windows as well. This ended up creating another user on my start up screen and other things that I just didn't like. While doing some digging I found Windows drivers for PostgreSQL here. I have since uninstalled the full PostgreSQL and installed the ODBC drivers which, thus far, work great.
To address the original question, after doing a bit more digging I think I found the equivalent ODBC for OS X here. I have not had a chance to try them out, but the concept works very well on Windows 7. I will update this when I get a chance to try them out. Until then, I hope this helps.
All from the above doesn't work for me (OS Catalina 10.15.1)
There was a conflict with classical postgres and homebrew version.
Please delete homebrew version by command
$ brew uninstall postgresql
and then install it from the official website:
$ sudo mkdir -p /etc/paths.d && echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp
It is actual for a simple psycopg2 install or django-heroku package.
if you have recently updated python or changed default python (let's say from 3.6 to 3.8). The following code
sudo apt-get install python-dev OR sudo apt-get install python3-dev
will be installing/working for the previous python version.
so if you want this command to work for the recently updated/changed python version try mentioning that specific version like python3.8 in command like
sudo apt-get install python3.8-dev
try above with following
pip install wheel
export PATH=/path/to/compiled/postgresql/bin:"$PATH"
sudo apt-get install libpq-dev
sudo apt-get install python3.x-dev **Change x with your version, eg python3.8**
pip install psycopg2-binary
pip install psycopg2
As I never needed to install postgresql database on this server I installed the following libraries on Ubuntu 14_04 version before running pip install psycopg2 on the same server
apt-get install libpq-dev python-dev
and then executed pip install psycopg2 within virtual env.
Output
Collecting psycopg2
Using cached psycopg2-2.6.1.tar.gz
Building wheels for collected packages: psycopg2
Running setup.py bdist_wheel for psycopg2
Stored in directory: /root/.cache/pip/wheels/e2/9a/5e/7b620848bbc7cfb9084aafea077be11618c2b5067bd532f329
Successfully built psycopg2
Installing collected packages: psycopg2
Successfully installed psycopg2-2.6.1
I know you are asking for development environment but if you are deploying on server say, Heroku.
Just add below line in the requirements.txt of your project.
django-heroku==0.3.1
As this package itself will install the required packages like psycopg2 on server deployment.
Try to specify the version and it'll works, do it inside the venv
pip install psycopg2-binary==2.8.6
based on my experience, apt install libpq-dev then try to install psycopg2 inside venv will fix many issues, however for more information you can refer to this link:
https://www.psycopg.org/docs/install.html