flake8 module installed but not un /usr/bin - flake8

I have installed flake8 successfully:
$ pip install flake8
Downloading/unpacking flake8
Downloading flake8-2.5.4-py2.py3-none-any.whl
Downloading/unpacking mccabe<0.5,>=0.2.1 (from flake8)
Downloading mccabe-0.4.0-py2.py3-none-any.whl
Downloading/unpacking pep8!=1.6.0,!=1.6.1,!=1.6.2,>=1.5.7 (from flake8)
Downloading pep8-1.7.0-py2.py3-none-any.whl (41kB): 41kB downloaded
Downloading/unpacking pyflakes<1.1,>=0.8.1 (from flake8)
Downloading pyflakes-1.0.0-py2.py3-none-any.whl (152kB): 152kB downloaded
Installing collected packages: flake8, mccabe, pep8, pyflakes
Successfully installed flake8 mccabe pep8 pyflakes
Cleaning up...
$ pip list|grep flake
flake8 (2.5.4)
pyflakes (1.0.0)
But it doesn't appear in any of the directories under /usr (/usr/bin/, /usr/sbin/, /usr/local/...) i.e. "which flake8" doesn't show anything, so I can't use from the console manually to verify a script like in the instructions.

You should look in ~/.local/ the pip you have installed (from Ubuntu's repositories) is modified to prevent the user from installing packages globally. You'll need to look for something like ~/.local/bin/flake8 and then you'll want to update your shell config to do something like
export PATH="~/.local/bin:$PATH"
So that it finds the executables you install with pip.

Related

Installing or updating a package using the pip in Python

If I accidentally run any of the following commands to install or update a package using pip in Python 3.x twice, will it install or update that package twice on the machine?
pip install <package_name>
pip install --upgrade <package_name>
After updating a package twice, it says that:
Requirement already satisfied: appnope in ./.pyenv/versions/3.11.0/lib/python3.11/site-packages (from ipykernel) (0.1.3)"
Does this mean I already updated or installed the package?
Yes, it means you have already installed or upgraded.
The first command installs the package. Because you have not specified a package version with something like pip install package-name==1.0.0, pip will install the package with the latest version.
The second command attempts to upgrade the same package. Because it is installed with the latest version, there is nothing to upgrade. pip will not reinstall packages unless you ask it to.
pip install --upgrade --force-reinstall <package-name>
pip will also attempt to install dependencies for your packages that may be required for the package you requested.
Requirement already satisfied: appnope in ./.pyenv/versions/3.11.0/lib/python3.11/site-packages (from ipykernel) (0.1.3)"

unable to locate pip packages using asdf in VSC

I have just installed a fresh install of BigSur and Python (using asdf) when installing pip packages they seem to end up in:
./.asdf/installs/python/3.9.2/lib/python3.9/site-packages
when typing which flake8 for example I get flake8 not found but when I go to install it again pip install flake8 I get the following:
> which flake8
flake8 not found
~
> pip install flake8
Requirement already satisfied: flake8 in ./.asdf/installs/python/3.9.2/lib/python3.9/site-packages (3.8.4)
Requirement already satisfied: pycodestyle<2.7.0,>=2.6.0a1 in ./.asdf/installs/python/3.9.2/lib/python3.9/site-packages (from flake8) (2.6.0)
Requirement already satisfied: mccabe<0.7.0,>=0.6.0 in ./.asdf/installs/python/3.9.2/lib/python3.9/site-packages (from flake8) (0.6.1)
Requirement already satisfied: pyflakes<2.3.0,>=2.2.0 in ./.asdf/installs/python/3.9.2/lib/python3.9/site-packages (from flake8) (2.2.0)
I have just tried to use requests which I installed like pip install requests and I also got not found when using which but I manage to use the package in VSC ok.
I am using flake8 and Black and I need to give VSC their paths. I have used
./.asdf/installs/python/3.9.2/lib/python3.9/site-packages/<package name>
but VSC doesn't seem to pip it up. I am using the latest verisons.
> python -V
Python 3.9.2
~
> pip -V
pip 21.0.1 from /Users/paul/.asdf/installs/python/3.9.2/lib/python3.9/site-packages/pip (python 3.9)
this might help too:
~
> which python
/Users/paul/.asdf/shims/python
~
> which pip
/Users/paul/.asdf/shims/pip
Any idea how I can get which to display the correct paths so I can get my listing and formatting working ok?
This fixed it... https://til.hashrocket.com/posts/ques11vrjs-get-pip-installed-executables-into-the-asdf-path
asdf reshim python
I would be curious why I have to do this...if anyone could answer

How to fix 'Could not find a version that satisfies the requirement' for install_requires list when pip installing in custom package?

I am trying to build my own Python package (installable by pip) using the twine package. This is all going well right up until the point where I try to pip install my actual package (so after uploading to PyPi).
So I first run:
python3 setup.py sdist bdist_wheel
In which my setup.py install_requires list looks like this:
install_requires=[
'jupyter_kernel_gateway==2.4.0',
'pandas==1.0.2',
'numpy==1.18.1',
'azure-storage-blob==2.0.1',
'azure-datalake-store==0.0.48',
'psycopg2-binary==2.8.4',
'xlsxwriter==1.2.6',
'SQLAlchemy==1.3.12',
'geoalchemy2==0.6.3',
'tabulate==0.8.2',
'pyproj==1.9.6',
'geopandas==0.4.0',
'contextily==0.99.0',
'matplotlib==3.0.2',
'humanize==0.5.1',
'ujson==1.35',
'singleton-decorator==1.0.0',
'dataclasses==0.6',
'xlrd==1.2.0'],
In my understanding, these install_requires would be installed by pip when installing my own package.
After this I run
python3 -m twine upload --repository testpypi dist/*
To actually upload my package to PyPi. However, when pip installing my package, I get errors that say there are no versions that satisfy the requirements for a lot of the listed requirements. E.g.: ERROR: Could not find a version that satisfies the requirement psycopg2-binary==2.8.4
When I manually install these packages (e.g. pip install psycopg2-binary==2.8.4), they do get installed.
Is there any way to make the pip install of my package actually install the install_requires requirement list succesfully?
You didn't show how your pip install-ing your package, but I'm guessing you're using something like:
pip install your_project --index-url https://test.pypi.org/simple
The issue is that TestPyPI doesn't contain copies of your dependencies that exist on PyPI. For example:
Exists: https://pypi.org/project/psycopg2-binary/2.8.4/
Does not exist: https://test.pypi.org/project/psycopg2-binary/2.8.4/
You can configure pip to fall back on TestPyPI when a package is missing instead by specifying --extra-index-url instead:
pip install your_project --extra-index-url https://test.pypi.org/simple

setuptools, use package on local system instead of getting it from PyPI

There is an open-source python package that I want to work on (toga-android). To test the code I write, I have to be able to build my own project that has said open-source package as a dependency. My project has to be built with setuptools, so I need setuptools to fulfill the dependency using my version of the package, and not get the package from PyPI.
The problem is that setuptools always gets the package from PyPI.
Whenever I build with setuptools I see:
Collecting toga-android==0.3.0.dev8
Downloading https://files.pythonhosted.org/packages/92/fe/348a39e2e0bbcac2d3ed511dd2b62943b488e7dcb8097c437416caf1c179/toga_android-0.3.0.dev8-py3-none-any.whl
or
Collecting toga-android==0.3.0.dev8
Using cached https://files.pythonhosted.org/packages/92/fe/348a39e2e0bbcac2d3ed511dd2b62943b488e7dcb8097c437416caf1c179/toga_android-0.3.0.dev8-py3-none-any.whl
Clearly it is getting the package from PyPI or using a cached version from it.
I have installed my version using pip install -e . , and that has no effect. I have also tried including the package's source in my project's directory with setup.py. Setuptools apparently includes this code because syntax errors there make the build fail, but it doesn't recognize that it can satisfy the dependency. It still gets the package from PyPI and any modules imported from the package are the PyPI versions.
How can I use of custom version of a package that is also in PyPI as a setuptools dependency?
Steps to reproduce:
pip install briefcase (using or not using virtualenv does not matter)
git clone https://github.com/pybee/toga.git
cd ~/toga/src/core; sudo pip install -e .
cd ~/toga/src/android/; sudo pip install -e .
cd ~/toga/examples/tutorial0
python setup.py android
The output will show that an older version of toga-android is downloaded even though it was already installed with pip.

pip uninstall: "No files were found to uninstall."

I have created a python module, call it 'foo_bar'.
I can install it and I can upgrade it, but I cannot uninstall it.
I build my module using bdist_wheel:
$ python3 setup.py bdist_wheel
And I install and upgrade it as follows:
$ python3 -m pip --timeout 60 install --upgrade dist/foo_bar-1.4.3-py3-none-any.whl
It is listed within Python 3.4 framework directory:
ls -al /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/
drwxr-xr-x 12 samwise admin 408 Jun 21 02:50 foo_bar
drwxr-xr-x 9 samwise admin 306 Jun 21 02:50 foo_bar-1.4.3.dist-info
And it listed within pip freeze:
$ python3 -m pip freeze
foo-bar==1.4.3
However, if I try to perform pip uninstall, it cannot find it's files
$ python3 -m pip uninstall foo-bar
Can't uninstall 'foo-bar'. No files were found to uninstall.
Did I do something wrong within my setup.py for it not to be able to find my modules files during uninstall?
Version info is as follows:
$ python3 --version
Python 3.4.4
$ python3 -m pip --version
pip 8.1.2 from /Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (python 3.4)
I had the same issue. Using verbose helped me to find out a bit more the reason:
$ pip3 uninstall --verbose my-homemade-package
Not sure how to uninstall: my-homemade-package e48e635 - Check: /home/olivier/my-homemade-package
Can't uninstall 'my-homemade-package'. No files were found to uninstall.
Removing everything that was 'my-homemade-package' related in /usr/local/python2.x and /usr/local/python3.x did not help.
I did a pip3 show my-homemade-package and got the location of the installed package on my computer:
$ pip3 show my-homemade-package
Name: my-homemade-package
Version: e48e635
Summary: My Home Made package
Home-page: UNKNOWN
Author: UNKNOWN
Author-email: UNKNOWN
License: Proprietary
Location: /home/olivier/my-homemade-package
Requires: pyOpenSSL, pyasn1, protobuf
Removing /home/olivier/my-homemade-package sorted it out the issue (ie: the package was not listed).
This is an old post, but it was top result in Google. The above answers are correct, however, in my case there was still line /usr/local/lib/python3.6/site-packages/easy-install.pth that I had to remove after also removing the egg files.
So I was having a similar issue to OP. I could install my package with pip install dist/mypackage.tar.gz. Installation would work fine, but at the end it would show Can't uninstall 'mypackage'. No files were found to uninstall., and indeed pip uninstall mypackage wouldn't work later on.
It sounds silly but what worked for me was to change working directory: once I left mypackage/ directory, pip uninstall mypackage worked.
I had such issue when I renamed my module in setup.py.
Old old_name.egg-info directory still existed in my_module directory. So, when I installed module with pip install -e . pip created a line in python3.8/site-packages/easy-install.pth pointing to module directory. After that module was listed by pip list with both names: new-name and old-name. And when I tried to remove old module with pip remove old-name pip showed error:
Found existing installation: old-name 0.3.0
Can't uninstall 'old-name'. No files were found to uninstall.
The solution was to remove directory old_name.egg-info from module directory. After that pip list shows only new-name.
Probably it is not direct answer to original post but one of the solutions for issue in topic-name.
Issue: User cannot uninstall a python package installed via pip:
pip uninstall youtube-dl
Found existing installation: youtube-dl 2021.12.17
Not uninstalling youtube-dl at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'youtube-dl'. No files were found to uninstall.
Reason: PEBKAC.
Well, a simple
apt purge youtube-dl
did the trick. There had been a system package "youtube-dl" installed, with said version:
dpkg -l youtube-dl
ii youtube-dl 2021.12.17-1~nd110+1
At the same time users used to install packages locally using pip. Both packages of the same version (2021.12.17). And both ways (apt and pip) referred to the packages by the same name. Turned out, this tends to confuse users..
Next level: Have a package installed three ways: apt, pip --system and plain pip as user. Maybe pip as root (locally) FWIW, too.

Resources