Local install / uninstall of PyQt (pip interface?) - python

The installation instructions for PyQt say:
python configure-ng.py
make
make install
I usually work on a personal virtualenv environment, and pip install -e <path_to_package_source_folder> allows me to install Python packages from source in a manner that allows me later to uninstall the package with pip uninstall <name_of_package>.
However, for PyQt, If I try:
python configure-ng.py
pip install -e .
it complains with No setup.py found.
Is there a way to build PyQt in a manner that allows for easy uninstall it later? (e.g. this could happen because that there is a new version of PyQt and I would like to upgrade to it)

Try to provide the -destdir argument (see the notes about PYTHONPAT), that should do the trick. I doubt PyQt4 supports installation via pip/setuptools/distribute.
To uninstall it later it should be enough to delete the installed files.

Related

Python versions mess not able to successfully install packages anymore

I am using Python version 3.11 with MacOS Ventura 13.1 (M1 chip) and cannot successfully install packages anymote. Upon installing them (apparently successfully) Python does not find them and is thus also not able to uninstall them.
I have a lot of research related and thus really important packages installed under a folder opt/homebrew/lib/python3.10/site-packages/
How can I get them to work with 3.11?
And a few more questions:
a) For some reason pip install doesn't work anymore, pip3 install does however, is that normal?
b) whenever I install something it says:
[notice] A new release of pip available: 22.3.1 -> 23.0
[notice] To update, run: python3.11 -m pip install --upgrade pip
user#MacBook-user ~ % python3.11 -m pip install --upgrade pip
Collecting pip
Using cached pip-23.0-py3-none-any.whl (2.1 MB)
Installing collected packages: pip
Successfully installed pip-23.0
[notice] A new release of pip available: 22.3.1 -> 23.0
[notice] To update, run: /opt/homebrew/opt/python#3.11/bin/python3.11 -m pip install --upgrade pip
so it kind of shows the message on repeat although it says, it has successfully installed pip.
I have already tried to uninstall and reinstall python, but it does not seem to work either.
(I also seem to have some issue with installing specific packages from time to time, which is why I assume something is off, but neither reinstalling nor upgrading has worked)
As per the comment:
which python3.11 shows /Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11 - how can I change my setup so it will work with my previous packages?
opt/homebrew/opt/python3.11 is an alias for /opt/homebrew/Cellar/python#3.11/3.11.1
Update:
since the whole M1 thing seems to be a mess, I un- and reinstalled brew, CommandLine Tools and python
I am running things on python 3.10.9 now, having it freshly installed it still says
[notice] A new release of pip available: 22.3.1 -> 23.0 [notice] To update, run: python3.10 -m pip install --upgrade pip
it now is:
which python3.10 /opt/homebrew/bin/python3.10
(regardless of whether I update like the above python3.10 -m pip install --upgrade pip or pip3 -m pip install --upgrade pip or python3 -m pip install --upgrade pip it will always keep complaining with the note above.
The Python interpreter that runs when you type python in your shell is determined by your PATH - unless you use the alias command, see note at bottom about why I suggest you do not use that.
Paths with the word "local" or "homebrew" in them are generally items installed by homebrew.
Paths starting with /Library or containing Frameworks are generally items supplied by Apple and should not be removed.
You appear to be running an Apple-supplied Python, so your PATH is wrong. If you want to run the homebrew Python, you need to run:
brew info Python
and read and do exactly what it says in respect of versioned links, unversioned links and your PATH.
Note that Python and pip versions are inextricably linked. You must run the pip that matches your Python or you will go around in circles updating the wrong one.
You can see which Python you'll run when entering python in your shell by running:
type python
Likewise, you can see which pip you'll start by running:
type pip
You can see which Python you are running from inside a script or inside an IDE, and also where it is looking for packages:
import sys
# Where is the Python I am running?
print(sys.executable)
# Where is it looking for packages?
print(sys.path)
# Where did it find Numpy, or any other package?
import numpy as np
print(np.__file__)
You can see where pip installed a package, say flask with:
pip show flask
Note: It is possible to define an "alias" like this:
alias python=/some/path/to/some/python
IMHO, that is a bad idea as aliases are not respected in:
cron jobs, so you'll get problems as soon as you try to run a Python process on a schedule
Python subprocesses, so you'll get problems as soon as you call suborocess.run(...)
IDEs, so you'll get problems when you use PyCharm, VS Code and so on.
Also, if you alias python to some version 3.10 but don't alias pip to the same version, you will get in a mess.
Note: homebrew installs its packages in its "Cellar" and then makes symbolic links (symlinks) to them from /usr/local/bin or /opt/homebrew/bin. In general, you should use the latter rather than directly using the binaries in the Cellar because then:
homebrew can manage the links to allow you to switch versions simply
you'll only need one PATH to allow you to use all homebrew packages

pip3 installs modules to location python3 can't find

I have pip3, installed via the yum install of python3-pip.
I've done a pip3 global install of some modules I need, but python3 can't find them to import. After a little investigation I see that pip3 installed the modules to /usrlib/python3.6/site-packages/pip/_vendor/
The problem is that python3 doesn't seem to know to look at pip/_vendor, it only finds modules directly installed under site-package. If I just copy the modules from .../site-package/pip/_vendor to .../site-package everything works fine.
The issue doesn't appear to be related to file permissions or ability to read the modules.
I'm wondering how I configure either pip to install directly to site-package or python3 to understand how to look in the pip/_vendor location.
I'm configuring this all with ansible and would like as module an option as possible. For instance I could manually use an argument to tell pip3 to install to the folder I want, but I don't want to hardcode the exact site-package directory if I don't have to.
I recommend starting over with pip by downloading and running get-pip.py. This will not only install the latest version of pip, but it will also install packages to a Python-readable location (the version of Python you use to run get-pip.py).
As an aside, I would avoid installing packages system-wide unless there is a specific need for them. At the very least, you should be installing them as a regular user, and even better you should be using a virtualenv.

Using pip to upgrade packages originally installed via apt

I would like to install the newest version of docutils via pip, but it can't figure out how to upgrade the system version installed via apt.
$ sudo --set-home python2 -m pip install --upgrade docutils
Collecting docutils
Using cached https://files.pythonhosted.org/packages/3a/dc/bf2b15d1fa15a6f7a9e77a61b74ecbbae7258558fcda8ffc9a6638a6b327/docutils-0.15.2-py2-none-any.whl
Installing collected packages: docutils
Found existing installation: docutils 0.14
ERROR: Cannot uninstall 'docutils'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
$ apt-cache show python-docutils | head -n 3
Package: python-docutils
Architecture: all
Version: 0.14+dfsg-3
None of the solutions I've thought of or found on the web appeal:
Delete the apt version with rm -rf /usr/lib/python2.7/dist-packages/docutils*. This silences pip but means:
Installed files on the system no longer match what the Debian packaging system thinks
I might break dependencies of system software on docutils 0.14
Any updates to the Debian package will cause apt to reinstall
Other problems discussed in this answer
pip install --force-reinstall. (Same problems.)
pip install --ignore-install. (Same problems.)
Is there a way to get a default environment that works for me with the newest versions of stuff from pip but has no chance of breaking any system software? The same answer above suggests using one of virtualenv, venv, pyenv, pipenv. I tried pipenv and it doesn't want to install individual packages listed on the commandline using --system and I don't know whether creating a Pipfile will actually solve this problem.
I would rather not have to manually switch environments somehow to use the apt-installed packages versus the pip-installed packages. Is there a way to get only apt-installed software to use one environment and otherwise use the environment with the pip-installed stuff?
I would rather not have to manually switch environments somehow to use the apt-installed packages versus the pip-installed packages. Is there a way to get only apt-installed software to use one environment and otherwise use the environment with the pip-installed stuff?
Ideally, one should use either the system version or the pip version.
Per the Debian Python Policy,
As long as you don't install other versions of Python in your path, Debian's Python versions won't be affected by a new version.
If you install a different micro version of the version of Python you have got installed, you will need to be careful to install all the modules you use for that version of Python too.
So far adding the following to ~/.bashrc seems work well:
if [ ! -d ~/venv/python3 ]; then
python3 -m venv --system-site-packages ~/venv/python3
fi
if [ -d ~/venv/python3 ]; then
VIRTUAL_ENV_DISABLE_PROMPT=1 . ~/venv/python3/bin/activate
fi
Most of the system-installed scripts have one of the Pythons in /usr/bin hard-coded instead of using /usr/bin/env python so they are unaffected by this.

Changing directory where pip installs packages

I have a python2.6 installed on Oracle linux.
I decided to use a newer python version and installed python 2.7.13.
I have also installed pip to manage packages.
Now if I use pip to install a package it still installs it to the old location: /usr/lib/python2.6/site-packages
Is there a way to force pip to install packages for the newer python 2.7 version?
Posable Repeat Post
"Use a version of pip installed against the Python instance you want to install new packages to.
In many distributions, there may be separate python2.6-pip and python2.7-pip packages, invoked with binary names such as pip-2.6 and pip-2.7. If pip is not packaged in your distribution for the desired target, you might look for a setuptools or easyinstall package, or use virtualenv (which will always include pip in a generated environment).
pip's website includes installation instructions, if you can't find anything within your distribution." ~Charles Duffy
Taken from How to install a module use pip for specific version of?
Did you check Install a Python package into a different directory using pip?.
To install in specified target directory use "pip install --target= "
Oracle Linux uses the system-installed version of Python for almost all of its command-line utilities, so changing that could irreparably damage your system.
Instead of replacing the default Python install, you should strongly consider using Python 2.7 from Software Collections instead.
Using Software Collections means that the install of Python 2.7 is separated from the system install, so you don't run the risk of damaging your system. You can then make it available to your applications via the scl tool.

Difference between 'python setup.py install' and 'pip install'

I have an external package I want to install into my python virtualenv from a tar file.
What is the best way to install the package?
I've discovered 2 ways that can do it:
Extract the tar file, then run python setup.py install inside of the extracted directory.
pip install packagename.tar.gz from example # 7 in https://pip.pypa.io/en/stable/reference/pip_install/#examples
Is if there is any difference doing them in these 2 ways.
On the surface, both do the same thing: doing either python setup.py install or pip install <PACKAGE-NAME> will install your python package for you, with a minimum amount of fuss.
However, using pip offers some additional advantages that make it much nicer to use.
pip will automatically download all dependencies for a package for you. In contrast, if you use setup.py, you often have to manually search out and download dependencies, which is tedious and can become frustrating.
pip keeps track of various metadata that lets you easily uninstall and update packages with a single command: pip uninstall <PACKAGE-NAME> and pip install --upgrade <PACKAGE-NAME>. In contrast, if you install a package using setup.py, you have to manually delete and maintain a package by hand if you want to get rid of it, which could be potentially error-prone.
You no longer have to manually download your files. If you use setup.py, you have to visit the library's website, figure out where to download it, extract the file, run setup.py... In contrast, pip will automatically search the Python Package Index (PyPi) to see if the package exists there, and will automatically download, extract, and install the package for you. With a few exceptions, almost every single genuinely useful Python library can be found on PyPi.
pip will let you easily install wheels, which is the new standard of Python distribution. More info about wheels.
pip offers additional benefits that integrate well with using virtualenv, which is a program that lets you run multiple projects that require conflicting libraries and Python versions on your computer. More info.
pip is bundled by default with Python as of Python 2.7.9 on the Python 2.x series, and as of Python 3.4.0 on the Python 3.x series, making it even easier to use.
So basically, use pip. It only offers improvements over using python setup.py install.
If you're using an older version of Python, can't upgrade, and don't have pip installed, you can find more information about installing pip at the following links:
Official instructions on installing pip for all operating systems
Instructions on installing pip on Windows (including solutions to common problems)
Instructions on installing pip for Mac OX
pip, by itself, doesn't really require a tutorial. 90% of the time, the only command you really need is pip install <PACKAGE-NAME>. That said, if you're interested in learning more about the details of what exactly you can do with pip, see:
Quickstart guide
Official documentation.
It is also commonly recommended that you use pip and virtualenv together. If you're a beginner to Python, I personally think it'd be fine to start of with just using pip and install packages globally, but eventually I do think you should transition to using virtualenv as you tackle more serious projects.
If you'd like to learn more about using pip and virtualenv together, see:
Why you should be using pip and virtualenv
A non-magical introduction to Pip and Virtualenv for Python beginners
Virtual Environments
python setup.py install is the analog of make install: it’s a limited way to compile and copy files to destination directories. This doesn’t mean that it’s the best way to really install software on your system.
pip is a package manager, which can install, upgrade, list and uninstall packages, like familiar package managers including: dpkg, apt, yum, urpmi, ports etc. Under the hood, it will run python setup.py install, but with specific options to control how and where things end up installed.
In summary: use pip.
The question is about the preferred method to install a local tarball containing a python package, NOT about the advantage of uploading package to an indexing service like PyPi.
As lest I know some software distributor does not upload their package to PyPi, instead asking developers to download package from their website and install.
python setup.py install
This can work but not recommended. It's not necessary to unwrap the tarball file and go into it to run setup.py file.
pip install ../path/to/packagename.tar.gz
This is the way designed and preferred. Concise and align with PyPi-style packages.
More information about pip install can be found here: https://pip.readthedocs.io/en/stable/reference/pip_install/

Categories