CS50W lecture7 testing,CI/CD--a problem about YAML and GitHub Actions - python

I am taking CS50’s Web Programming with Python and JavaScript(CS50W) course. I am now having a problem for lecture 7 Testing, CI/CD. When I followed along Brian in the GitHub Actions section(Timestamp at about 1:13:36), the result in my GitHub Actions turned out not to be the same with his.
This is the yaml code( I exactly copied from the lecture) :
name: Testing
on: push
jobs:
test_project:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Run Django unit tests
run:
pip3 install --user django
python manage.py test
In his GitHub Actions there was nothing wrong about the "run django unit tests" part. But Mine turned out to have some errors. My result in GitHub Actions showed as this(Click to see the screenshot):
Run pip3 install --user django python manage.py test
pip3 install --user django python manage.py test
shell: /usr/bin/bash -e {0}
Collecting django
Downloading Django-4.0.3-py3-none-any.whl (8.0 MB)
ERROR: Could not find a version that satisfies the requirement python (from versions:
none)
ERROR: No matching distribution found for python
Error: Process completed with exit code 1.
So I thought there was something wrong for setting up django or python in the GitHub Ubuntu virtual machine, then I tried to get rid of the python manage.py test syntax in the yaml file, and the "run django unit tests" in GitHub Actions turned out no errors. The result showed as(Click to see the screenshot)
Run pip3 install --user django
pip3 install --user django
shell: /usr/bin/bash -e {0}
Collecting django
Downloading Django-4.0.3-py3-none-any.whl (8.0 MB)
Collecting asgiref<4,>=3.4.1
Downloading asgiref-3.5.0-py3-none-any.whl (22 kB)
Collecting backports.zoneinfo; python_version < "3.9"
Downloading backports.zoneinfo-0.2.1-cp38-cp38-manylinux1_x86_64.whl (74 kB)
Collecting sqlparse>=0.2.2
Downloading sqlparse-0.4.2-py3-none-any.whl (42 kB)
Installing collected packages: asgiref, backports.zoneinfo, sqlparse, django
Successfully installed asgiref-3.5.0 backports.zoneinfo-0.2.1 django-4.0.3 sqlparse-
0.4.2
It seems django was successfully installed. But what went wrong when the python manage.py test syntax was added in the yaml file? I completely have no idea. Can someone point it out? Thanks a lot! You might wanna have a look at my GitHub repository for this. If your need more infomation please just tell me. THANKS!!!

The error message you were getting indicates that it tried to install python in:
ERROR: No matching distribution found for python
but python refers to your second command, python manage.py test
So the error message indicates that it is trying to run two commands as one single command.
When running multiple commands, you have to include the | character, so Github Actions understands that there are multiple commands to be run. In the lecture you can see that Brian included the necessary | character:
run: |
pip3 install --user django
python manage.py test

Related

Pre-release version number in mixed python/rust project with maturin

I am working on a mixed Rust/Python project being build with maturin. I am having trouble figuring out how I can specify a pre-release version that can than be installed by pip.
The start of my Cargo.toml is
[package]
version = "0.0.1-test.1"
When I do maturin build --release, it creates my_project-0.0.1_test.1-cp39-cp39-macosx_10_7_x86_64.whl. Note that 0.0.1-test.1 in the version was changed to 0.0.1_test.1 in the name of the wheel file. (The dash became an underscore.)
If I publish this to my Nexus server and try to install it in a separate project, pip gives an error:
$ pip install my_project==0.0.1_test.1
Looking in indexes: ...
ERROR: Could not find a version that satisfies the requirement my_project==0.0.1_test.1 (from versions: 0.0.1-test.1, 0.0.1.dev1)
If I try it with a dash instead of an underscore:
pip install py_mod_query_builder==0.0.1-test.1
Looking in indexes: ...
ERROR: Exception:
<stack trace>
pip._vendor.packaging.version.InvalidVersion: Invalid version: '0.0.1-test.1'
If I change the version in Cargo.toml to 0.0.1_troy.1, then Cargo fails to parse the build file:
$ maturin build --release
🍹 Building a mixed python/rust project
💥 maturin failed
Caused by: Cargo metadata failed. Do you have cargo in your PATH?
Caused by: Error during execution of `cargo metadata`: error: failed to parse manifest at `/Users/me/my-project/Cargo.toml`
Caused by:
unexpected character '_' after patch version number for key `package.version`
I did have some success with pip install path/to/my_project*.whl. However, that is difficult to incorporate into building a docker image. The wheel is outside the project with the Dockerfile, so docker will not be able to find it without jumping through a bunch of hoops, while downloading it from the server during the docker build is simple, but fails due to the dash/underscore problem.
Additionally, while both projects are being developed, I would like the CI pipeline for the development branch to use the pre-release version. Getting access to the wheel file (without having pip download it) is nearly impossible in that situation.
It seems that Cargo insists on the format being #.#.#-string and pip insists on it being #.#.#_string. Is there a way to make both of them happy?
Versions:
Installing project
pip 22.1
python 3.9.12
Building project
pip 20.0.4
python 3.9.12
maturin 0.8.3
rustc 1.56.1 (59eed8a2a 2021-11-01)

can't find my packages from pycharm/heroku

I have deployed a package into https://pypi.org/project/core-lib/0.0.1.dev1/
But pycharm or heroku can't find my package with this error message
Can you help me, please?
Thank you
Pycharm
No matching package version found: 'core-lib==0.0.1.dev1' (required: ==0.0.1.dev1, installed: <nothing>, latest: <nothing>)
heroku deploy
-----> Installing requirements with pip
ERROR: Could not find a version that satisfies the requirement core-lib==0.0.0.8 (from -r /tmp/build_c6b601b1/requirements.txt (line 1)) (from versions: none)
ERROR: No matching distribution found for core-lib==0.0.0.8 (from -r /tmp/build_c6b601b1/requirements.txt (line 1))
! Push rejected, failed to compile Python app.
! Push failed
Installed your package from pypi using PyCharm, and I am able to find it
(randomtesting) C:\Users\User\PycharmProjects\randomtesting>pip list
Package Version
---------------------- -------------------
core-lib 0.0.1.dev1
Perhaps the file was released into pypi very recently?
And I checked the link again, now it has the latest version.
Maybe try this?
pip install core-lib
You've declared that your package must be used under Python >= 3.7. Please make sure you use Python with high enough version. For example, I tried to install the package with Python 2.7 and pip failed to find the project. With Python 3.7 it was installed successfully.

Pip: could not find a version. No matching distribution found

I'm trying to install Flask-ACL:
https://mikeboers.github.io/Flask-ACL
$ pip search acl | grep -i flask
Flask-ACL (0.0.1) - Access control lists for Flask.
flask-miracle-acl (0.2) - The fabric between the Flask framework and Miracle ACL
Flask-Sandbox (0.1.0)- ACL Route controls for Flask
Flask-SimpleACL (1.2)- Simple ACL extension
$ pip install Flask-ACL
Collecting Flask-ACL
Could not find a version that satisfies the requirement Flask-ACL (from versions: )
No matching distribution found for Flask-ACL
What's wrong here?
P.S. Pip was upgraded a few minutes ago.
UPDATE:
$ python --version
Python 2.7.3
I'm running it under virtualenv.
pip install -Iv Flask-ACL
Collecting Flask-ACL
1 location(s) to search for versions of Flask-ACL:
* https://pypi.python.org/simple/flask-acl/
Getting page https://pypi.python.org/simple/flask-acl/
Looking up "https://pypi.python.org/simple/flask-acl/" in the cache
Current age based on date: 507
Freshness lifetime from max-age: 600
Freshness lifetime from request max-age: 600
The response is "fresh", returning cached response
600 > 507
Analyzing links from page https://pypi.python.org/simple/flask-acl/
Could not find a version that satisfies the requirement Flask-ACL (from versions: )
Cleaning up...
No matching distribution found for Flask-ACL
As I can see, there is no such package on Pypi:
https://pypi.python.org/simple/flask-acl/
but this one exist:
https://pypi.python.org/pypi/Flask-ACL
What is wrong with my pip?
The developers of Flask-ACL made a mistake that they did not manage to upload the Flask-ACL library onto PyPi(where pip searches for modules). so you will have to install it using pip from their GitHub page.
You can do so like this:
pip install "git+https://github.com/mikeboers/Flask-ACL"
A more common reason for this type of error is probably that your environment does not meet the package's requirements.
For example, this occurs if your environment's Python version does not match the required Python version specified by the package:
(my_python36_env)> pip install package_that_requires_python37
ERROR: Could not find a version that satisfies the requirement package_that_requires_python37.
ERROR: No matching distribution found for package_that_requires_python37.
Pay attention if your file ~/.pip/pip.conf not contain any additional index-url values.
Then it can trying to look for specific package version in repository that not exists.
Some workaround solution is to remove pip.conf
I had flask installed in the anaconda but it had some issues when it import it using
from tensorflow.keras.applications.imagenet_utils import preprocess_input, decode_predictions
so instead of the above command, i changed it to
from tensorflow.python.keras.applications.imagenet_utils import preprocess_input, decode_predictions
and it worked fine

Could not find a version that satisfies the requirement <package>

I'm installing several Python packages in Ubuntu 12.04 using the following requirements.txt file:
numpy>=1.8.2,<2.0.0
matplotlib>=1.3.1,<2.0.0
scipy>=0.14.0,<1.0.0
astroML>=0.2,<1.0
scikit-learn>=0.14.1,<1.0.0
rpy2>=2.4.3,<3.0.0
and these two commands:
$ pip install --download=/tmp -r requirements.txt
$ pip install --user --no-index --find-links=/tmp -r requirements.txt
(the first one downloads the packages and the second one installs them).
The process is frequently stopped with the error:
Could not find a version that satisfies the requirement <package> (from matplotlib<2.0.0,>=1.3.1->-r requirements.txt (line 2)) (from versions: )
No matching distribution found for <package> (from matplotlib<2.0.0,>=1.3.1->-r requirements.txt (line 2))
which I fix manually with:
pip install --user <package>
and then run the second pip install command again.
But that only works for that particular package. When I run the second pip install command again, the process is stopped now complaining about another required package and I need to repeat the process again, ie: install the new required package manually (with the command above) and then run the second pip install command.
So far I've had to manually install six, pytz, nose, and now it's complaining about needing mock.
Is there a way to tell pip to automatically install all needed dependencies so I don't have to do it manually one by one?
Add: This only happens in Ubuntu 12.04 BTW. In Ubuntu 14.04 the pip install commands applied on the requirements.txt file work without issues.
Although it doesn't really answers this specific question. Others got the same error message with this mistake.
For those who like me initial forgot the -r: Use pip install -r requirements.txt the -r is essential for the command.
The original answer:
https://stackoverflow.com/a/42876654/10093070
I had installed python3 but my python in /usr/bin/python was still the old 2.7 version
This worked (<pkg> was pyserial in my case):
python3 -m pip install <pkg>
This approach (having all dependencies in a directory and not downloading from an index) only works when the directory contains all packages. The directory should therefore contain all dependencies but also all packages that those dependencies depend on (e.g., six, pytz etc).
You should therefore manually include these in requirements.txt (so that the first step downloads them explicitly) or you should install all packages using PyPI and then pip freeze > requirements.txt to store the list of all packages needed.
Just a reminder to whom google this error and come here.
Let's say I get this error:
$ python3 example.py
Traceback (most recent call last):
File "example.py", line 7, in <module>
import aalib
ModuleNotFoundError: No module named 'aalib'
Since it mentions aalib, I was thought to try aalib:
$ python3.8 -m pip install aalib
ERROR: Could not find a version that satisfies the requirement aalib (from versions: none)
ERROR: No matching distribution found for aalib
But it actually wrong package name, ensure pip search(service disabled at the time of writing), or google, or search on pypi site to get the accurate package name:
Then install successfully:
$ python3.8 -m pip install python-aalib
Collecting python-aalib
Downloading python-aalib-0.3.2.tar.gz (14 kB)
...
As pip --help stated:
$ python3.8 -m pip --help
...
-v, --verbose Give more output. Option is additive, and can be used up to 3 times.
To have a systematic way to figure out the root causes instead of rely on luck, you can append -vvv option of pip command to see details, e.g.:
$ python3.8 -u -m pip install aalib -vvv
User install by explicit request
Created temporary directory: /tmp/pip-ephem-wheel-cache-b3ghm9eb
Created temporary directory: /tmp/pip-req-tracker-ygwnj94r
Initialized build tracking at /tmp/pip-req-tracker-ygwnj94r
Created build tracker: /tmp/pip-req-tracker-ygwnj94r
Entered build tracker: /tmp/pip-req-tracker-ygwnj94r
Created temporary directory: /tmp/pip-install-jfurrdbb
1 location(s) to search for versions of aalib:
* https://pypi.org/simple/aalib/
Fetching project page and analyzing links: https://pypi.org/simple/aalib/
Getting page https://pypi.org/simple/aalib/
Found index url https://pypi.org/simple
Getting credentials from keyring for https://pypi.org/simple
Getting credentials from keyring for pypi.org
Looking up "https://pypi.org/simple/aalib/" in the cache
Request header has "max_age" as 0, cache bypassed
Starting new HTTPS connection (1): pypi.org:443
https://pypi.org:443 "GET /simple/aalib/ HTTP/1.1" 404 13
[hole] Status code 404 not in (200, 203, 300, 301)
Could not fetch URL https://pypi.org/simple/aalib/: 404 Client Error: Not Found for url: https://pypi.org/simple/aalib/ - skipping
Given no hashes to check 0 links for project 'aalib': discarding no candidates
ERROR: Could not find a version that satisfies the requirement aalib (from versions: none)
Cleaning up...
Removed build tracker: '/tmp/pip-req-tracker-ygwnj94r'
ERROR: No matching distribution found for aalib
Exception information:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/pip/_internal/cli/base_command.py", line 186, in _main
status = self.run(options, args)
File "/usr/lib/python3/dist-packages/pip/_internal/commands/install.py", line 357, in run
resolver.resolve(requirement_set)
File "/usr/lib/python3/dist-packages/pip/_internal/legacy_resolve.py", line 177, in resolve
discovered_reqs.extend(self._resolve_one(requirement_set, req))
File "/usr/lib/python3/dist-packages/pip/_internal/legacy_resolve.py", line 333, in _resolve_one
abstract_dist = self._get_abstract_dist_for(req_to_install)
File "/usr/lib/python3/dist-packages/pip/_internal/legacy_resolve.py", line 281, in _get_abstract_dist_for
req.populate_link(self.finder, upgrade_allowed, require_hashes)
File "/usr/lib/python3/dist-packages/pip/_internal/req/req_install.py", line 249, in populate_link
self.link = finder.find_requirement(self, upgrade)
File "/usr/lib/python3/dist-packages/pip/_internal/index/package_finder.py", line 926, in find_requirement
raise DistributionNotFound(
pip._internal.exceptions.DistributionNotFound: No matching distribution found for aalib
From above log, there is pretty obvious the URL https://pypi.org/simple/aalib/ 404 not found. Then you can guess the possible reasons which cause that 404, i.e. wrong package name. Another thing is I can modify relevant python files of pip modules to further debug with above log. To edit .whl file, you can use wheel command to unpack and pack.
After 2 hours of searching, I found a way to fix it with just one line of command. You need to know the version of the package (Just search up PACKAGE version).
Command:
python3 -m pip install --pre --upgrade PACKAGE==VERSION.VERSION.VERSION
Below command worked for me -
python -m pip install flask
Not always, but in some cases the package already exists. For example - getpass. It is not listed by "pip list" but it can be imported and used:
If I try to pip install getpass I get the following error:
"Could not find a version that satisfies the requirement getpass"
Try installing flask through the powershell using the following command.
pip install --isolated Flask
This will allow installation to avoide environment variables and user configuration.
If you facing this issue at the workplace. This might be the solution for you.
pip install -U <package_name> --user --proxy=<your proxy>
Pip install from pypi.org.
pip install -U -i https://pypi.org/simple package
One possible error, pip package requires python intepreter which you are not using.
I ran into the same problem, it occurred only when I ran commands from my Docker image (or Dockerfile). Finally many hours later I managed to solve it by updating my python intepreter. Pointed out that my pip-package required python>=3,7 but my Docker image was using python 3.6.
Tip: To check out if you have similar problem, just check pip package requirements and your python version. Private pip package intepreter requirements are wrote down inside setup.py or setup.cfg. Public pip packages are usuially hosted in pypi.org where you can just check intepreter requirements with your browser. To check your python intepreter version just write for example python --version or python3 --version in your console
General problem description
As other answers point out there can also be other requirements that you are not satisfying and that is why pip can not found suitable package version for you. All the requirements are wrote down in pip package documentation and can be easily readed from https://pypi.org/project/graphene-django/your-package
I got this error while installing awscli on Windows 10 in anaconda (python 3.7).
While troubleshooting, I went to the answer https://stackoverflow.com/a/49991357/6862405 and then to https://stackoverflow.com/a/54582701/6862405. Finally found that I need to install the libraries PyOpenSSL, cryptography, enum34, idna and ipaddress. After installing these (using simply pip install command), I was able to install awscli.
When I lost my internet connection, I had this error.
Since it's a pretty annoying problem that may stuck beginners for a long period of time, here I write a complete guild.
if you are running pip install PACKAGE or python -m pip install PACKAGE, and a no matching version found error reported, here's how to solve the problem.
search your package on browser, for example my package is pycypto, here I search pycypto pypi
find your package, open the link on pypi, click download file
open a python shell, import any of your installed package, for example, I have installed Pillow before.
>>> import PIL
>>> PIL.__path__
['/Applications/MAMP/htdocs/canvas/src/zzd/env/lib/python3.7/site-packages/PIL']
PACKAGE.__path__ function will gives you the side packages path where all packages should go into.
PLUS:
if you have no idea what packages you installed before, run pip list to get a list of installed packages.
after we obtain the path, open a shell, cd to the path
cd /Applications/MAMP/htdocs/canvas/src/zzd/env/lib/python3.7/site-packages/
open
unzip the downloaded file, drag it into site-packages.
cd into the downloaded directory, and run setup.py to install
cd pycrypto-2.6.1
python setup.py install
Then you should be able to import and use the package in python.
Same error in slightly different circumstances, on MacOs. Apparently setuptools versions past 45 can expose some issues and this command got me past it:
pip3 install setuptools==45
If the package is local, don't miss the relative path.
E.g.
pip install ./<pkg>
finally worked in my case, while
pip install <pkg>
yielded:
ERROR: Could not find a version that satisfies the requirement <pkg> (from versions: none)
ERROR: No matching distribution found for <pkg>
I had a problem installing pandas-1.4.3, and the problem was my python patch version. pandas-1.4.3 required python version 3.8.13 and did not work with 3.8.9:
python install -r requirements.txt # or pip install pandas==1.4.3
# -> Could not find a version that satisfies...
conda activate my_project # creates a virtual env for a new python version
conda install python=3.8.13 # installing the new python version
python --version # displays 3.8.13
pip install -r python/requirements.txt
# -> pandas installed as expected
Search in google if you find some other version of that package available
use that for example
I was getting errors using the glob so I used glob2 instead

getting updated distribute via pip requirements file

im using pip requirements file for the dependencies with virtualenv. im using ubuntu10.04LTS now the problem has come up with djangorestframework, after adding it in .pip file
while downloading the requirements #URLObject error occurs and says
Downloading/unpacking URLObject>=0.6.0 (from djangorestframework->-r /var/lib/myproj/base.pip (line 26))
Using download cache from /usr/local/pipcache/http%3A%2F%2Fpypi.python.org%2Fpackages%2Fsource%2FU%2FURLObject%2FURLObject-2.0.1.tar.gz
Running setup.py egg_info for package URLObject
The required version of distribute (>=0.6.24) is not available,
and can't be installed while this script is running. Please
install a more recent version first, using
'easy_install -U distribute'.
(Currently using distribute 0.6.10 (/var/lib/myproj/.ve/lib/python2.6/site-packages/distribute-0.6.10-py2.6.egg))
Complete output from command python setup.py egg_info:
The required version of distribute (>=0.6.24) is not available,
and can't be installed while this script is running. Please
install a more recent version first, using
'easy_install -U distribute'
(Currently using distribute 0.6.10 (/var/lib/myproj/.ve/lib/python2.6/site-packages/distribute-0.6.10-py2.6.egg))
my pip requirement file is as follows:
virtualenv
django
distribute
django-permissions
django-storages
django-sentry
#django-db-utils
PIL
#Required for APIs
djangorestframework
i have even tried by adding distribute-0.6.25 but in vain how do i upgrade distribute via pip requirements file.
I just hit the same issue.
Solved by running:
pip install -U distribute==0.6.25
I don't think you can update it via the requirements file because requirements are installed at once and not one by one.
if you need distribute to be 0.6.25 version, just specify it in the requirements:
virtualenv
django
distribute==0.6.25
django-permissions
django-storages
django-sentry
#django-db-utils
PIL
#Required for APIs
djangorestframework

Categories

Resources