venv and pipenv not producing the same environment - python

While trying to build the documents of pydantic I came across a problem setting up a virtual environment using pipenv.
Following the steps described in here by samuelcolvin worked just fine:
# Using pyenv + vevn
cd code/pydantic
git checkout master
git pull
pyenv install 3.9.13
pyenv shell 3.9.13
python3 -m venv env-3.9.13
source env-3.9.13/bin/activate
make install
make install-docs
make docs
However, trying to set up the environment using pipenv fails. The steps I took are:
# Using pyenv + pipenv
pyenv install 3.9.13
pipenv --python 3.9
pipenv shell
make install
make install-docs
make docs
The last part fails with the following error:
flake8 --max-line-length=80 docs/examples/
python docs/build/main.py
error in hypothesis_property_based_test.py: Traceback (most recent call last):
File "/Users/drorata/dev/pydantic/docs/examples/hypothesis_property_based_test.py", line 2, in <module>
from hypothesis import given, strategies as st
AttributeError: type object 'Path' has no attribute '_flavour'
1 errors, not writing files
make: *** [docs] Error 1
I appreciate that this is a very specific issue, but maybe by solving it me and others could learn something important about pipenv.

Related

Pip is not found after creating new python virtual environment

I'm trying to create new Python virtual environment, but I have problems with pip.
I want my virtual environment to run on Python 3.10, but my default system Python version is 3.9.5. So I downloaded Python 3.10 with
sudo apt-get install python3.10
and then i run
python3 -m virtualenv venv --python=python3.10
to create virtual environment.
The problem is, when I try to use pip I get an error:
Traceback (most recent call last):
File "/home/<my user name>/venv/bin/pip", line 5, in <module>
from pip._internal.cli.main import main
ModuleNotFoundError: No module named 'pip'
I tried running
python -m ensurepip --upgrade
but got an error:
/home/pablo/venv/bin/python: No module named ensurepip
Also running whereis pip shows, that there are some pips in the virtual environment.
pip: /usr/bin/pip /home/<my user name>/venv/bin/pip3.10 /home/<my user name>/venv/bin/pip /usr/share/man/man1/pip.1.gz
Also, when I create virtual environments with my default python interpreter, everything works perfectly fine.
I would recommend using pyenv with pyenv-virtualenv. In my experience it's just too much work to go manual. Sorry I know this is not a true answer, but having wasted hours and hours on similar issues, I feel like sharing )
your installed binary executable is named as pip3.10(/usr/bin/pip /home//venv/bin/pip3.10). So you should use the same name to call it, just pip wouldn't work. Have you tried that?

Using Fabric 2 and Fabric 3 in the same project

I am currently using Fabric3 in a python project and I want to use the azure-cli package. However when I install the package, it appears to break my Fabric3 install:
root ~ $ fab --version
Traceback (most recent call last):
File "/opt/rh/rh-python36/root/usr/bin/fab", line 7, in
from Fabric3.main import program
ModuleNotFoundError: No module named 'Fabric3'
I noticed that the pip install of azure-cli appears to install fabric (2.5.0), and this appears to overwrite some of the fabric files within the "/opt/rh/rh-python36/root/usrbin/fab" script and the "/opt/rh/rh-python36/root/usr/lib64/python3.6/site-packages/fabric/" directory.
So my question is, is there a way to run different versions of Fabric within the same project?
Thanks in advance
I found a way to do this by using python virtual environments.
I created a virtual env, activated the virtual env, installed the pip package, deactivated the virtual env, then used Fabric 3 to call the function in the venv.
python -m venv azure_cli_venv
. azure_cli_venv/bin/activate
pip install azure-cli
deactivate
Fabric3 local call:
local(f'./azure_cli_venv/bin/az --help

I'm not sure if I'm installing GUDHI correctly

I'm following this guide to install GUDHI for python. I ran the following commands
cd /path-to-gudhi/
mkdir build
cd build/
cmake ..
cd python
make
After that, the guide says to do
cd /path-to-gudhi/build/python
# May require sudo or administrator privileges
make install
But when I run the make install nothing happens, it only returns
Install the project...
-- Install configuration: ""
And I don't really know if I'm doing something wrong (it's my first time installing a python module). When in python I type
import gudhi
it returns
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'gudhi'
Also when I do
make test
on the command line, it returns
Running tests...
Test project /home/alex/gudhi.3.0.0/build/python
No tests were found!!!
What could have gone wrong?
Installing all the dependencies and make it compile can be complicated.
Would the gudhi conda package fill your need ? You would just need to install Miniconda first (in Python 3.X).
And more recently, a gudhi pip package is also available.

Python venv (virual environment) uses wrong version of Python

I have both Python 3.7 and 3.6 installed. But in my profile I set to use 3.6 and this is indeed a version that gets reported by which python3.
$ which python3
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3
I then create virtual env by running python3 -m venv venv
And everything in my venv gets linked to the 3.6. I confirm this with ls -la venv/bin and by inspecting venv/pyvenv.cfg.
I activate the venv virtual environment.
I then install a zappa library with pip install zappa.
And when I run zappa deploy, I get an error that Python 3.7 is not supported. Why would a library use the version of Python that is not configured within the virtualenv and how do I make it use the correct version?
(venv) $ zappa deploy
Traceback (most recent call last):
File "/Users/t/Projects/djzappa/Spheres/venv/bin/zappa", line 7, in <module>
from zappa.cli import handle
File "/Users/t/Projects/djzappa/Spheres/venv/lib/python3.7/site-packages/zappa/__init__.py", line 12, in <module>
raise RuntimeError(err_msg)
RuntimeError: This version of Python (3.7) is not supported!
Zappa (and AWS Lambda) support the following versions of Python: ['2.7', '3.6']
NOTE: I do NOT use virtualenv as everybody is suggesting, and as other existing answers are referring.
Use this when you create environment:
virtualenv --python=/usr/bin/python3.6
But if you want to use venv, first of all, check whether python3 in your terminal refers to the python3.6 as you want.
If not - run your command with the full path to python3.6 instead of sole python3 in python3 -m venv venv.
Edit: why your alias python3 is referring to python3.7 - it probably depends on OS you use and sequence of installation. Hard to say.
As an addition to the accepted answer, be also aware that changing the directory name where your venv is located causes using the default python and pip paths of your system, instead of using the venv one.
The Python version is different from the virtualenv python version and that is why it is complaining.
You can recreate your virtual environment(delete the existing one) and use the following command
virtualenv --python=your python version here venv
Or
mkvirtualenv venv --python=your python version here
if you want to create your virtual environment using mkvirtualenv command.

Does the pip option "--force-reinstall" recompiles a module? (I'm trying to reinstall cx_Oracle)

My setup has:
- oracle-instantclient (downgraded from 12 to 11)
- Virtual Environment with Python + Django + cx_Oracle
When I downgraded the oracle-instantclient, I tried to reinstall cx_oracle using:
pip install --upgrade --force-reinstall cx_Oracle
The problem is that cx_Oracle keeps complaining that I'm not using the previous installed version 12:
$ python -c "import cx_Oracle"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: libclntsh.so.12.1: cannot open shared object file: No such file or directory
So, some questions here: "--force-reinstall" is not supposed to make a full reinstall, including a module recompile (aka cx_Oracle)? Somebody has some suggestion about how to workaround this issue? I looked at the pip manual and just tells me that it reinstalls the package. Not very useful.
Update1:
I tried to follow the solution here, adding my cx_Oracle path to the LD_LIBRARY_PATH but it's still not working.
echo $LD_LIBRARY_PATH
/usr/lib/oracle/11.2/client64/lib:/home/myuser/myuserenv/lib/python3.5/site-packages/cx_Oracle-5.2.1.dist-info
Note that my root user has a different python while my virtualenv uses its own python installation.
[root#myserver]# which python
/usr/bin/python
From my virtual environment:
(myvirtualenv) [myuser#myserver]$ which python
~/myvirtualenv/bin/python
Is there some way of installing cx_Oracle manually using my root user but putting the files at the virtual environment somehow?
Update2:
I tried to download cx_Oracle and compile manually using the following command:
sudo -u myuser ~/myvirtualenv/bin/python setup.py build install
But now I'm seeing some permission errors:
(...)
error: could not create 'build/bdist.linux-x86_64/egg': Permission denied
Am I doing the right thing? I don't want to mess this environment. Thanks.
The answer to your question (although you seem to have had another problem) is as follows:
It depends on the module's structure. If its setup script calls the compiler, then yes it does. Because, you see, pip modules by default do not include compiled parts, it's up to the module author to provide them.
I could finally install. The problem is that I had to use the python of my virtualenv. A simple solution but that I completely missed.
Steps:
pip download cx_Oracle
tar -xvf cx_Oracle-5.2.1.tar.gz
~/myenv/bin/python setup.py -v build
sudo ~/myenv/bin/python setup.py install
Note that I had to use sudo in the last step. Without this I was having this permission error:
error: could not create 'build/bdist.linux-x86_64/egg': Permission denied

Categories

Resources