I can't install graphene-django in GitHub actions - django

I am building a Django project, and I am using GitHub actions to run python manage.py test whenever I push. The problem is that in the project, I am using the graphene-django package, which's available to install via pip install graphene-django. The problem is that, for some reason, this doesn't seem to work (it outputs an error). I have tried everything:
pip install graphene-django
pip install "graphene-django>=2.0"
pip install --user graphene-django
pip install --user "graphene-django>=2.0"
pip3 install graphene-django
pip3 install "graphene-django>=2.0"
pip3 install --user graphene-django
pip3 install --user "graphene-django>=2.0"
Some of these commands display a different error, but the most common is this:
Collecting promise>=2.1 (from graphene-django>=2.0)
Downloading https://files.pythonhosted.org/packages/cf/9c/fb5d48abfe5d791cd496e4242ebcf87a4bb2e0c3dcd6e0ae68c11426a528/promise-2.3.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'setuptools'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-5vr1pems/promise/
Here is my YAML file for the Action (with the last intslling attempt):
name: Testing
on: push
jobs:
test_vote:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Run Django unit tests
run: |
pip3 install --user django
pip3 install --user "graphene-django>=2.0"
python3 manage.py test
env:
# Random key
SECRET_KEY: '!nj1v)#-y)e21t^u#-6tk+%+#vyzn30dp+)xof4q*y8y&%=h9l'
Any help would be really appreciated, since I've been in this for like an hour, when in the course, the teacher took like 5 minutes.
Thanks!

Install the module setuptools before installing graphene-django.

Related

How to install django with python3.9 on ubuntu aws

I'm having challenges installing django using the command sudo python3.9 -m pip install Django. The error I get running that command is:
Traceback (most recent call last):
File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/usr/lib/python3/dist-packages/pip/__main__.py", line 19, in <module>
sys.exit(pip.main())
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 217, in main
return command.main(cmd_args)
File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 242, in main
with self._build_session(
File "/usr/lib/python3/dist-packages/pip/basecommand.py", line 66, in _build_session
session = PipSession(
File "/usr/lib/python3/dist-packages/pip/download.py", line 321, in __init__
self.headers["User-Agent"] = user_agent()
File "/usr/lib/python3/dist-packages/pip/download.py", line 93, in user_agent
zip(["name", "version", "id"], platform.linux_distribution()),
AttributeError: module 'platform' has no attribute 'linux_distribution'
It's been a hard time trying to run sudo python manage.py migrate. From the comment/answer from this Stack Overflow post Traceback while running 'sudo python3 manage.py migrate' I got to know that I need python 3.6 and above. When I created the aws ubuntu server instance I ran python3 -V and the ouput was that python3.5 was running on the machine. I upgraded it to python 3.9. Now when I run python3 -V the output is: Python 3.9.4. After upgrading to python3.9 I created and activated another virtual enviroment.
Now when I try to install django using the command sudo python3.9 -m pip install Django I get the above error. If I use sudo python3 -m pip install Django the django is installed with python3.5 because, thereafter when I run sudo python3 manage.py migrate it throws back an error pointing to File "/usr/lib/python3.5/runpy.py", line 197, in _run_module_as_main If I delete python 3.5 in /usr/lib folder (since I still have python 3.9 there), python3.5 is recreated in the /usr/lib folder whenever I reinstall django using sudo python3 -m pip install Django (even if python3 -V is outputting Python 3.9.4). When I run sudo python3 manage.py migrate it says I don't have django installed in my enviroment variable.
Now the explanation is getting boring. PLEASE HOW DO I INSTALL DJANGO ON UBUNTU AWS USING PYTHON3.9?
sudo apt-get install python3-setuptools
sudo apt remove python3-pip
sudo python3.9 -m easy_install pip
then try to install django again
python3 -m pip install Django
Don't forget to create a virtual environment and specify the python version first
I later found out that it is not possible to run sudo python3.9 -m pip install Django. As stated in the stack overflow post found in the link Traceback while running 'sudo python3 manage.py migrate', python3.5 does not support it.
I had to install python3.6. I was able to use this python version to install django by runnig sudo python3.6 -m pip install Django.
I'm definitely not satisfied with these sorts of breaking changes that exist with python releases, but I'm glad I got the program running.

Why django is not installing on ubuntu?

I am trying to install django using pipenv but failing to do so.
pipenv install django
Creating a virtualenv for this project...
Pipfile: /home/djangoTry/Pipfile
Using /usr/bin/python3.9 (3.9.5) to create virtualenv...
⠴ Creating virtual environment...RuntimeError: failed to query /usr/bin/python3.9 with code 1 err: 'Traceback (most recent call last):\n File "/home/.local/lib/python3.6/site-packages/virtualenv/discovery/py_info.py", line 16, in <module>\n from distutils import dist\nImportError: cannot import name \'dist\' from \'distutils\' (/usr/lib/python3.9/distutils/__init__.py)\n'
✘ Failed creating virtual environment
[pipenv.exceptions.VirtualenvCreationException]:
Failed to create virtual environment.
Other info
python --version
Python 2.7.17
python3 --version
Python 3.6.9
python3.9 --version
Python 3.9.4
pip3 --version
pip 21.1 from /home/aman/.local/lib/python3.6/site-packages/pip (python 3.6)
Please help.Thanks
The problem isn't with installing Django, is on creating your venv, I don't create on this way so I will pass the way that i create
Step 1 - Install pip
Step 2 - Install virtaulEnv
check here how to install both
after installed, run python3 -m venv venvthis wil create an venv on your current directory. Initiate them with . venv/bin/activateand so run pip install django. That should work
Try pipenv install --python 3.9

Cloud build pytest Can not find Ghostscript library

I'm trying to create a trigger that test a function before deploying it in cloud function. So far I managed to install requirements.txt and execute pytest but I get the following error:
/usr/local/lib/python3.7/site-packages/ghostscript/__init__.py:35: in <module>
from . import _gsprint as gs
/usr/local/lib/python3.7/site-packages/ghostscript/_gsprint.py:515: in <module>
raise RuntimeError('Can not find Ghostscript library (libgs)')
E RuntimeError: Can not find Ghostscript library (libgs)
I have ghostscript in my requirements.txt file :
[...]
ghostscript==0.6
[...]
pytest==6.0.1
pytest-mock==3.3.1
Here is my deploy.yaml
steps:
- name: 'docker.io/library/python:3.7'
id: Test
entrypoint: /bin/sh
dir: 'My_Project/'
args:
- -c
- 'pip install -r requirements.txt && pytest pytest/test_mainpytest.py -v'
From the traceback, I understand that I don't have ghostscript installed on the cloud build, which is true.
Is there a way to install ghostscript on a step of my deploy.yaml?
Edit-1:
So I tried to install ghostscript using commands in a step, I tried apt-get gs, apt-get ghostscript but unfortunately it didn't work
The real problem is that you are missing a c-library, the package itself seems installed by pip. You should install that library with your package manager. This is an example for ubuntu-based containers:
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'bash'
args:
- '-c'
- |
apt update
apt install ghostscript -y
pip install -r requirements.txt
pytest pytest/test_mainpytest.py -v

Installing pip package through .ebextensions

I am having trouble installing the package psycopg2 through ebextensions.
00_software.config
packages:
yum:
git: []
htop: []
pip:
psycopg2: []
01_setup_pg_activity.config
commands:
clone:
command: git clone https://github.com/dalibo/pg_activity.git
install_psycopg2:
command: cd pg_activity && python setup.py install
Alternatively, I have also tried this to no avail
commands:
clone:
command: git clone https://github.com/dalibo/pg_activity.git
install_psycopg2:
command: pip install psycopg2
install_psycopg2:
command: cd pg_activity && python setup.py install
The other software installs but pip packages will not
Traceback (most recent call last):
File "/usr/local/bin/pg_activity", line 4, in <module>
__import__('pkg_resources').run_script('pg-activity==1.6.1', 'pg_activity')
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 742, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/usr/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 1510, in run_script
exec(script_code, namespace, namespace)
File "/usr/local/lib/python2.7/site-packages/pg_activity-1.6.1-py2.7.egg/EGG-INFO/scripts/pg_activity", line 42, in <module>
ImportError: No module named psycopg2
I have to manually go in and run sudo pip install psycopg2 for it to correctly install. How can I do this in the build process?
If you are using a virtual environment and EB CLI, simply creating requirements.txt will be enough while the virtual environment is active. EB CLI handles the package installations on deployment.
Using EB with AL2 (python env; haven't tested on RoR), successfully installed pg_activity.
For packages (only psycopg2 shown) I had
packages:
yum:
python-psycopg2: []
And the commands config file was (20_setup_pg_activity.config):
commands:
05_clone:
command: git clone https://github.com/dalibo/pg_activity.git
10_install_pg_activity:
command: cd pg_activity && python setup.py install
Following the env setup, I logged into the EB instance to check if pg_activity exists (only part shown):
ec2-user#ip-172-31-82-127 ~]$ pg_activity --help
Usage: pg_activity [options]
htop like application for PostgreSQL server activity monitoring.
Options:
--version show program's version number and exit
-U USERNAME, --username=USERNAME

How to reinstall Django

For some reasons I removed Django
first I entered
>> import django
>> django.__path__
and then I entered
sudo rm -r path
in terminal.
And now when I'm trying to reinstall it I enter these commands
$ sudo apt-get update
$ sudo apt-get install python3-django
i see
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-django is already the newest version (1:1.11.11-1ubuntu1.8).
0 upgraded, 0 newly installed, 0 to remove and 5 not upgraded.
And then I enter
django-admin --version
i see
Traceback (most recent call last):
File "/usr/local/bin/django-admin", line 5, in
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
What should I do to reinstall it?
You can try to install Django using this command:
pip3 install Django
Like how we have pip install <filename> to install a package.
Similarly, to uninstall a package, you can do pip uninstall <filename>
in your case,
to install Django : pip install django
to Uninstall Django : pip uninstall django