I'm running Mypy inside a gitlab CI/CD, and mypy can't find installed stubs, even though I've tried to use the --install-types option.
I've also tried creating a virtual env and install all packages, setting up the MYPYPATH and/or PYTHONPATH with the directory where the packages are installed, but I ended up with the same errors.
Here is the output of the CI worker:
mypy --install-types --non-interactive backoffice coupons
Requirement already satisfied: types-pytz in ./dev_packages (2022.2.1.0)
Requirement already satisfied: types-requests in ./dev_packages (2.28.11)
Requirement already satisfied: types-urllib3<1.27 in ./dev_packages (from types-requests) (1.26.25)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
[notice] A new release of pip available: 22.2 -> 22.3
[notice] To update, run: python -m pip install --upgrade pip
coupons/models.py:4: error: Library stubs not installed for "pytz" (or incompatible with Python 3.10)
Installing missing stub packages:
/usr/local/bin/python -m pip install types-pytz types-requests
Found 3 errors in 3 files (checked 66 source files)
coupons/models.py:4: note: Hint: "python3 -m pip install types-pytz"
coupons/utils.py:6: error: Library stubs not installed for "requests" (or incompatible with Python 3.10)
backoffice/accounts.py:8: error: Library stubs not installed for "requests" (or incompatible with Python 3.10)
backoffice/accounts.py:8: note: Hint: "python3 -m pip install types-requests"
backoffice/accounts.py:8: note: (or run "mypy --install-types" to install all missing stub packages)
backoffice/accounts.py:8: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
make: *** [.make/lint.mk:57: mypy] Error 1
Does anyone faced this issue before and how did you fixed it?
Thanks
Related
I'm setting up a RHEL8 (8.7) based Docker container, with Python 3.8.13 installed (installed python3-pip, python3.6, python 3.8 and 3.9 too). I have tried to install some Python libraries using requirements.txt:
RUN pip3 install -r requirements.txt
The txt file is recognized, some of the requirements are found and installed, but some of them are exiting with the failure code: 1
For example, I want to install joblib 1.2.0 and numpy 1.23.2, so my requirements.txt file has the following entries too:
joblib == 1.2.0
numpy == 1.23.2
But the build exits with the following as soon as it reaches the "joblib" line:
Collecting joblib==1.2.0 (from -r requirements.txt (line1))
Could not find a version that satisfies the requirement joblib==1.2.0 (from -r requirements.txt (line1)) (from versions: 0.3.2d.dev, ..*omitting a massive list of versions*.. 1.1.0, 1.1.1)
No matching distribution found for joblib==1.2.0 (from -r requirements.txt (line1))
error building image: error building stage: failed to execute command: waiting for process to exit: exit status 1
I have tried to install EPEL and probably install Python 3.10 or 3.11 but did not succeed, probably not supported by RHEL8.
I have gone through the following checks advised for cases when pip does not find the correct version:
pip install -r requirements.txt command is indeed running with the -r option.
version of pip is pip3, matching the installed Python3
name of the module is not misspelled, correct
the listed modules are not built-in modules (they indeed have to be installed separately)
package does support the version of Python:
Joblib 1.2.0 supported Python versions are 3.7+ (as stated, 3.8 and 3.9 is installed too)
Numpy 1.23.2 supported Python versions are 3.8-3.11
So these should be visible for pip3 installer - yet they are not, Joblib max offered version is 1.1.1...
Is there a workaround or solution for this?
I have a directory with scripts *.py that I need to compile on another computer that includes different versions of modules. I opened the terminal in that directory and have created requirements:
pip freeze > requirements.txt
Then I created a vertual environment and tried to installed packages from requirements.txt
virtualenv compilation
source compilation/bin/activate
python3.6 -m pip install -r requirements.txt
It ended with this:
ERROR: Cannot install babel==2.7.0, gitsome==0.8.4 and pytz==2021.1 because these package versions have conflicting dependencies.
The conflict is caused by:
The user requested pytz==2021.1
babel 2.7.0 depends on pytz>=2015.7
gitsome 0.8.4 depends on pytz<2017.0 and >=2016.3
To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict
ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/user_guide/#fixing-conflicting-dependencies
Why is there a conflict when these packages work in non-virtual python3.6, please? What to do with that, please?
After babel and gitsome upgrade
ERROR: Cannot install babel==2.7.0, gitsome==0.8.4, pandas==1.1.5 and pytz==2016.10 because these package versions have conflicting dependencies.
The conflict is caused by:
The user requested pytz==2016.10
babel 2.7.0 depends on pytz>=2015.7
gitsome 0.8.4 depends on pytz<2017.0 and >=2016.3
pandas 1.1.5 depends on pytz>=2017.2
To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict
ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/user_guide/#fixing-conflicting-dependencies
Downgrading pytz
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
pandas 1.1.5 requires pytz>=2017.2, but you have pytz 2015.7 which is incompatible.
gitsome 0.8.4 requires pytz<2017.0,>=2016.3, but you have pytz 2015.7 which is incompatible.
Successfully installed pytz-2016.10
Removed build tracker: '/tmp/pip-req-tracker-8c5_ezeo'
You may want to try downgrading pytz
pip install -Iv pytz==2017.0
or upgrading babel and gitsome
sudo pip install babel --upgrade
sudo pip install gitsome --upgrade
I have just started using python and I have set up python3 to be installed in C:\Python37 dir. I have added python3 path to environment variables. When I run python3 -m pip install [package_name] it installs it in C:\Python37\Lib\site-packages. But when I try to install pylint with python3 -m pip install pylint it prints:
Requirement already satisfied: pylint in c:\users\radio\appdata\roaming\python\python37\site-packages (2.3.1)
It's installing it in above mentioned completely different location, and then VS Code complains how pylint is not installed. Why doesn't pip install it in C:\Python37\Lib\site-packages where it installs all the other packages?
It seems you might have multiple python installations on the computer or you are not running CMD with administrator priviledges when using pip.
I would refer you to this thread: windows pip installing libraries in wrong directory which seems to deal with a problem similar to the one you are having.
I would also try checking the environment variables to see the path set for Python if that doesn't work.
I'm creating a new Python virtual environment with Python's 3.5 built-in virrtualenv package:
D:\Projects>python -m venv --system-site-packages proj_3
D:\Projects>cd proj_3
D:\Projects\proj_3>Scripts\activate.bat
(proj_3) D:\Projects\proj_3>pip install comtypes
Collecting comtypes
Downloading comtypes-1.1.2.zip (179kB)
100% |################################| 184kB 569kB/s
Installing collected packages: comtypes
Running setup.py install for comtypes ... done
Successfully installed comtypes-1.1.2
(proj_3) D:\Projects\proj_3>dir Lib\site-packages
Volume in drive D has no label.
Volume Serial Number is 0E52-CE22
Directory of D:\Projects\proj_3\Lib\site-packages
20.05.2016 14:15 <DIR> .
20.05.2016 14:15 <DIR> ..
0 File(s) 0 bytes
2 Dir(s) 268,620,853,248 bytes free
So I want to reuse existing system packages and install new package in my created virtualenv. But instead, although I'm in virtualenv, pip installed the package in my system libraries instead in local project.
(proj_3) D:\Projects\proj_3>where pip
C:\Python35\Scripts\pip.exe
(proj_3) D:\Projects\proj_3>python -m ensurepip
Ignoring indexes: https://pypi.python.org/simple
Requirement already satisfied (use --upgrade to upgrade): setuptools in c:\python35\lib\site-packages
Requirement already satisfied (use --upgrade to upgrade): pip in c:\python35\lib\site-packages
It looks like pip is not bootstraped in my local package because it already exists in my system packages. Unless I did something wrong, this is unexpected as using virtualenv with Python 2 does not behave like this.
Any ideas what might be wrong?
It is a bug already reported here: https://bugs.python.org/issue24875
Before it is fixed, try this workaround.
First, create the virtual environment without --system-site-packages. Then modify the created environment.
pyvenv /path/to/env && pyvenv --system-site-packages /path/to/env
I have just started using virtualenv from this tutorial, where it uses yolk to list the packages installed in the virtualenv, but yolk by default is for Python 2, so I decided to upgrade with an extension for Python 3, my current version, with the following command:
pip3 install --upgrade yolk3k
It works when I am not in the virtualenv that I called virt0, but if I am on it, it gives me the error it was giving me before upgrading it to the Python 3 version.
print " %s %s (%s)" % (project_name, dist.version,
^
SyntaxError: invalid syntax
When I tried to install yolk in the virt0, the output was the following:
Searching for yolk
Best match: yolk 0.4.3
Processing yolk-0.4.3-py3.4.egg
yolk 0.4.3 is already the active version in easy-install.pth
Installing yolk script to /Users/user/Desktop/virt_env/virt0/bin
Using /Users/user/Desktop/virt_env/virt0/lib/python3.4/site-packages/yolk-0.4.3-py3.4.egg
Processing dependencies for yolk
Finished processing dependencies for yolk
In /Users/user/Desktop/virt_env/virt0/bin, I have this:
activate pip3
activate.csh pip3.4
activate.fish python
activate_this.py python3
easy_install python3.4
easy_install-3.4 yolk
pip
which confirms that yolk was installed, but how can I update it also to yolk3k in virt0?
If I try to install yolk3k with the following command:
pip3 install --upgrade yolk3k
inside /Users/user/Desktop/virt_env/virt0/bin, it outputs:
Requirement already up-to-date: yolk3k in /Users/user/Desktop/virt_env/virt0/lib/python3.4/site-packages
but it still gives me the error I cited above.
Delete the virtualenv, recreate it with Python 3 as the interpreter and install all dependencies for Python 3 (such as yolk3k). The problem seems to come from the fact that you're going from a 2.x to a 3.x environment even though the virtualenv originally wasn't.
That's not the intended way of using a virtualenv - a virtualenv should be tied to one particular Python version (e.g., 2.7 or 3.4) with all dependencies installed for that version. So you should throw away the virtualenv and rebuild it entirely using 3.x dependencies. That should resolve any conflicting language issues.