Getting pip pystruct==0.3.2 to build under python=3.7 - pip

There is no current solution for building pystruct 0.3.2 under python=3.7 because of an issue with support for python<=3.6 and resulting in a build time error related to curexc_traceback not being found. Also the utils.pyx file is not circulated with the pip tarball, resulting in an inability to rebuild the cython package that appears in the github version, as opposed to the pypi version. How can we patch and build pystruct==0.3.2 from pip?

It turns out that if you combine the github version and pypi version, you can find a way that allows you to build the pip version as follows:
#!/usr/bin/env bash
VERSION=0.3.2
pip download pystruct==${VERSION}
git clone https://github.com/pystruct/pystruct
tar xzf pystruct-${VERSION}.tar.gz
mv pystruct-${VERSION}/src/utils.c pystruct-${VERSION}/src/utils.save
cp pystruct/src/utils.pyx pystruct-${VERSION}/src/
cython pystruct-${VERSION}/src/utils.pyx
cd pystruct-${VERSION} && python ./setup.py install

Related

pip install from local directory doesnt add [build-system] dependencies

In our project (Locust) we use setuptools_scm for versioning, so it is needed for all installations from local directory.
We used to have this specified in setup.py:
setup(
setup_requires=["setuptools_scm>=6.2"],
...
)
But we have upgraded to use setup.cfg and pyproject.toml
[build-system]
requires = ["setuptools_scm>=6.2", ...]
This works nicely in most cases, but it does not install setuptools_scm if someone does pip install -e . (it doesnt work for pip install . either but that is less important)
With no setuptools_scm installed the local version becomes 0.0.0:
~/git/locust pip install -e .
Looking in indexes: https://pypi.org/simple
...
Running setup.py develop for locust
Successfully installed locust-0.0.0
... and that makes me very sad.
What is the appropriate way make pip install setuptools_scm when installing from source?
I could of course add it as a regular dependency in setup.cfg, but that would make thousands of users download setuptools_scm even when it is not needed (when installing from PyPi)

How to upgrade pyenv (macOS) such that a fresh .venv contains an up-to-date pip?

I'm trying to prevent this warning every time I create a fresh .venv:
> /Users/pi/.pyenv/versions/3.10.0/bin/python -m venv .venv
> . .venv/bin/activate
> pip install ipykernel # or anything
WARNING: You are using pip version 21.2.3; however, version 22.2.2 is available.
You should consider upgrading via the '/Users/pi/code/foo/.venv/bin/python -m pip install --upgrade pip' command.
Somehow pyenv has populated my fresh .venv with an out-of-date pip.
If I execute the suggested command it will upgrade my .venv's pip. But I don't want to be doing that every time I create a .venv.
I figured this might fix it, but it doesn't:
> /Users/pi/.pyenv/versions/3.10.0/bin/python -m pip install --upgrade pip
Requirement already satisfied: pip in /Users/pi/.pyenv/versions/3.10.0/lib/python3.10/site-packages (22.2.1)
Collecting pip
Using cached pip-22.2.2-py3-none-any.whl (2.0 MB)
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 22.2.1
Uninstalling pip-22.2.1:
Successfully uninstalled pip-22.2.1
Successfully installed pip-22.2.2
What is actually happening when I execute the above command? I was expecting it to update the pip for the python version created/maintained by pyenv. Which it seems to be doing:
🧢 pi#pPro18-4 ~/.pyenv/versions/3.10.0
> find . -name 'pip*'
./bin/pip3
./bin/pip
./bin/pip3.10
./lib/python3.10/site-packages/pip
./lib/python3.10/site-packages/pip-22.2.2.dist-info
🧢 pi#pPro18-4 ~/.pyenv/versions/3.10.0
> ./bin/pip --version
pip 22.2.2 from /Users/pi/.pyenv/versions/3.10.0/lib/python3.10/site-packages/pip (python 3.10)
So why isn't this pip getting copied into my .venv when I create it?
I thought that was the way .venv creation worked.
How to clean up my pyenv Python installation so that it spawns up-to-date .venvs?
EDIT:
Insight from #python on IRC/Libera:
grym: I don't think you can; i just get in the habit of python -m venv somevenv && somevenv/bin/python -m pip install --upgrade pip setuptools wheel
jinsun: python -m venv --upgrade-deps .venv is a simple solution if you were just annoying by the pip warning (...) it is updating the pip inside the venv, forget about the base python, I don't even have pip in the base python
This is the use case for pyenv-hooks
pyenv-hooks are scripts that are executed by pyenv whenever certain commands are run. You can create hooks for regular commands like: exec, rehash, which, but it can also be a plugin command, like virtualenv. The scripts can be written in any language.
Here is the wiki with official instructions.
You can have a hook by creating a script at the following location:
$PYENV_ROOT/pyenv.d/<hook-name>/<your-script-name>
For example, to create a hook that upgrades pip, create a new script within this path:
$PYENV_ROOT/pyenv.d/virtualenv/after.bash
With contents:
after_virtualenv 'PYENV_VERSION="$VIRTUALENV_NAME" pyenv-exec pip install --upgrade pip'
after_virtualenv is the command that tells pyenv when to execute. First, it sets the pyenv version to the name of the virtualenv we just created. with the variable $VIRTUALENV_NAME. Then it upgrades pip itself.
More details in this article.
I originally posted it as a comment, but was suggested to make it a proper answer.
An easier approach is to use the upgrade-deps flag when you create a virtual environment. Like this:
python3 -m venv --upgrade-deps .venv
It was added on python3.9, and according to the official docs:
--upgrade-deps
Upgrade core dependencies (pip, setuptools) to the latest version in PyPI
So, in other words, it will install pip and upgrade right away.

pip trying to install using old version of python

so I just uninstalled a wrong version of python 3.8 and downloaded python 3.7.4
Now I'm trying to install packages using the command pip install X and get the following error.
C:\Users\User>pip install cv2
Fatal error in launcher: Unable to create process using '"c:\users\user\appdata\local\programs\python\python38-32\python.exe" "C:\Users\User\AppData\Local\Programs\Python\Python38-32\Scripts\pip.exe" install cv2': The system cannot find the file specified.
clearly it is still trying to use the old version of python 3.8 even though I have uninstalled it and reinstalled pip several times.
Any idea on why its trying to look for this old path? and how can I change the default path it is using?
(btw this is just a matter of convenience because as of the moment if I use the command python -m pip install X it does seem to work)
try command python -m pip install --upgrade pip
Delete and clear environment config and install again...

python3 venv pip version conflict

I have a PyCharm python 3.7.1 project on Windows 10. In the project venv\Scripts folder is pip.exe, pip3.exe, etc. If I list pip's version while standing in that folder I get:
me#my-machine MINGW64 ~/PycharmProjects/myProject/venv/Scripts (develop)
$ ./pip --version
pip 10.0.1 from c:\users\me\pycharmprojects\myProject\venv\lib\site-packages\pip-10.0.1-py3.7.egg\pip (python 3.7)
me#my-machine MINGW64 ~/PycharmProjects/myProject/venv/Scripts (develop)
$ ./python --version
Python 3.7.1
me#my-machine MINGW64 ~/PycharmProjects/myProject/venv/Scripts (develop)
$ ./python -m pip --version
pip 18.1 from C:\Users\me\PycharmProjects\myProject\venv\lib\site-packages\pip (python 3.7)
I seem to have a version mismatch. Can I safely delete the pip-10.0.1-py3.7.egg folder? Do I need to do anything else?
You shouldn't delete any files in your site-packages folder. Besides the two pip executables you tested are different. The one loaded with python -m pip will most probably point to the pip3 binary and not the pip one.

pytables installation failed

I do:
sudo pip install --upgrade tables
I get:
/usr/bin/ld: cannot find -lhdf5
collect2: ld returned 1 exit status
.. ERROR:: Could not find a local HDF5 installation.
You may need to explicitly state where your local HDF5 headers and
library can be found by setting the ``HDF5_DIR`` environment
variable or by using the ``--hdf5`` command-line option.
Complete output from command python setup.py egg_info:
/usr/bin/ld: cannot find -lhdf5
however:
$ echo $HDF5_DIR
/opt/hdf5/
$ ls /opt/hdf5/
bin include lib share
$ ls /opt/hdf5/lib/
libhdf5.a libhdf5_hl.la libhdf5_hl.so.8 libhdf5.la libhdf5.so libhdf5.so.8.0.1
libhdf5_hl.a libhdf5_hl.so libhdf5_hl.so.8.0.1 libhdf5.settings libhdf5.so.8
What's wrong? How to debug? I already tried to set HDF5_DIR to /opt/ or to /opt/hdf5/lib.
I also had the same error on Debian sid trying to work in a local virtualenv. To work around it I did:
apt-get build-dep python-tables
HDF5_DIR=/usr/lib/x86_64-linux-gnu/hdf5/serial/ && pip install tables
... now it's working.
I was able to fix this easily in OSX with virtual environments using the following code:
$ brew install hdf5
$ pyvenv test
$ workon myvenv # to get pytables working within the virtual environment myvenv
$ pip install numpy numexpr cython
$ pip install tables
(taken from andreabedini post in https://github.com/PyTables/PyTables/issues/385)
I'm having a similar problem, but I'm using the leading edge not the pip release (see Aside).
I also tried pointing to the library itself
export HDF5_DIR=/usr/lib/libhdf5.so.6
but it did not work.
Aside: You can try the leading edge of PyTables if you think your bug may have been addressed recently:
sudo pip install git+https://github.com/PyTables/PyTables
.
The build (that was caused by pip install...) seemed to progress further after I installed the dev version of the hdf5 library (libhdf5-openmpi-dev). The build still failed for other reasons, but it's another direction you could try.
Perhaps you can install the stable wheel file for your os for pytables from here:
http://www.lfd.uci.edu/~gohlke/pythonlibs/#pytables
Use this command to check for which file to download
path/to/pythonX.Y -m pip debug --verbose
And this command to install the wheel file
pip install C:/some-dir/some-file.whl
I tried everything without success. The only way I could I achieved was using nehalecky's answer I got here:
https://github.com/PyTables/PyTables/issues/219
In a nutshell, you should do these 2 commands, correcting the path, of course:
sudo python3 setup.py build_ext --inplace --hdf5=/usr/lib/x86_64-linux-gnu/hdf5/serial/
sudo python3 setup.py install --hdf5=/usr/lib/x86_64-linux-gnu/hdf5/serial/
Hope it helps!

Resources