5

I am currently trying to install a requirements and it is telling me that it is not found when I try and comment them out it happens for others.

I just deployed a Ubuntu 18.04 server. Made the virtual env by the following command python3 -m venv --system-site-packages env but every single time I try and run pip install -r requirements.txt it fails with

Collecting apparmor==2.12 (from -r requirements.txt (line 1))
  Could not find a version that satisfies the requirement apparmor==2.12 (from -r requirements.txt (line 1)) (from versions: )
No matching distribution found for apparmor==2.12 (from -r requirements.txt (line 1))

if I try and install say pip install apparmor it tells me

Collecting apparmor
  Could not find a version that satisfies the requirement apparmor (from versions: )
No matching distribution found for apparmor

But then if I comment out apparmor it tells me this

Collecting apturl==0.5.2 (from -r requirements.txt (line 2))
  Could not find a version that satisfies the requirement apturl==0.5.2 (from -r requirements.txt (line 2)) (from versions: )
No matching distribution found for apturl==0.5.2 (from -r requirements.txt (line 2))

and it goes on for others randomly. The requirements was made on my local which is also ubuntu 18 so unsure why this works on local but not on a new deploy.

I have also made sure that it's the newest version of pip

hoefling
  • 59,418
  • 12
  • 147
  • 194
nadermx
  • 2,596
  • 7
  • 31
  • 66
  • 1
    `apparmor` and `apturl` are not available from PyPI, they are part of Ubuntu packages and can only be installed via `apt install apparmor`/`apt install apturl`. You have probably frozen the system site packages. – hoefling Apr 29 '19 at 22:05
  • @hoefling This was the issue, if you want to make it a answer – nadermx Apr 29 '19 at 23:13

3 Answers3

11

apparmor and apturl are Ubuntu packages, you can safely ignore them if your code doesn't use their code; just remove them from requirements.txt. If your code depends on them, ensure they are installed via apt:

apt install -y apparmor apturl && pip install -r requirements.txt
hoefling
  • 59,418
  • 12
  • 147
  • 194
  • do you know why they are included in the requirements.txt if they are not needed by the project? – HAL9000 Aug 24 '21 at 16:43
  • 1
    @hal9000 if you mean the generation of `requirements.txt` via e.g. `pip freeze`, then it doesn't distinct between packages actually used in your code or not. It simply collects everything that is installed according to PEP 376. It's best to craft the requirements manually anyway. – hoefling Aug 24 '21 at 17:02
8

This is a common problem when you don't use virtual enviroment for work with python, so your requirements.txt lists all the packages pythons of your system or OS, when you must have only the packages from your project. In some moment you update your requirements.txt with pip freeze > requirements.txt, without a virtual environment and you updated the requirements.txt with all python packages in your OS and from your project, and maybe uploaded to a repository. So when you want to run in another computer and install all packages you got this kind of error...

Python is installed by default in ubuntu, you must consider this and in other system too.

  1. First rule is work every time with virtual enviroment "virtual env documentation"
  2. I know it's hard work, but you can backup that requirements.txt and clean it. Then try to run your program without any package (a clean install) and when errors occurs from missing packages you add it and update with pip freeze > requirements.txt
cigien
  • 57,834
  • 11
  • 73
  • 112
Felipe Illanes
  • 419
  • 5
  • 8
0

The solution is ignoring the builtin libraries that already exist and can't be downloaded by pypi if you need to change them you will need to change python version .so the workaround i used is running each line of requirements file separately so that unfound error do not stop all process of installs. here is the code .if you need any question just ask i m pro i can help you

import subprocess   #Builtin python librarie that will wil used to run commands
with open('requirements.txt') as f: # Opening requirements file
 t=f.read().split("\n") # Spliting the contents of requirements to array of  strings
for e in t: #Creating loop ot iter over each line (element of array)
 subprocess.run("python -m pip install "+e)  #Running the process of python install libraries
Bahae El Hmimdi
  • 364
  • 1
  • 5