Why django is not installing on ubuntu? - django

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

Related

I can't install graphene-django in GitHub actions

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.

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

Why is "-m" needed for "python -m pip install ..."?

I recently used pip to install the requests package in python 2.7, however in order to do so I had to use:
python -m pip install requests
instead of just:
python pip install requests
which gave me an error:
can't open file 'pip: [Errno 2] No such file or directory
Why did I need to add the -m?
python -m pip tells python to run with the pip module as the main module.
python pip isn't understood, because pip isn't a command line argument that python understands (i.e., pip is a module).
If the python scripts directory (c:\python27\scripts for python 2.7 on windows) is on your path, then you can just run pip (without python before it) and pass the same options you would pass to python -m pip.
So: you need to add -m pip so python knows what module to use as the main module. pip is a standalone program installed in your python scripts directory, not an argument to python.

No module named django.core.management,error while installing django in vm

When I try to run my server using:
./manage.py runserver 0.0.0.0:8000
I get the following error:
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
After browsing for a solution, I learned that Django was not installed so I tried installing it on a VM.
I tried the following:
pip install django
yum install django
yum install python-django
I also tried running these commands with sudo -s and sudo -E.
I am getting the following when I use pip cmd:
Downloading/unpacking django
Cannot fetch index base URL https://pypi.python.org/simple/
Could not find any downloads that satisfy the requirement django
No distributions at all found for django
Storing complete log in /root/.pip/pip.log
Using Yum I get:
No package python-django available.
Error: Nothing to do
Install a new version of Python. Pip has to be installed for the new
version. CentOS 6.6 has default Python 2.6 and the default pip
doesn't work properly.
Install Django with new pip.
Do not install the new version of Python globally as CentOS relies on
Python 2.6 for yum.

Installing django on two existing versions on python

I have both python 2.7 and 3.2 installed on my computer and I wanted to install django. And when I did it automatically installed django 1.4 on python 3. Is there a way I can install it on python 2.7?
You can mention explicitly the python version while installing.
First download the source from django website.
Now extract it to any location and open the terminal and go to the location into the folder. There must be a file named setup.py that is the installation file.Now type:
For Python 3.2
python3.2 setup.py install
For Python 2.7
python2.7 setup.py install
The real answer here is that you should be using virtual environments, as they both solve this particular problem, and are the industry standard because they solve many problems.
Simple process:
install python-virtualenv :
$>sudo apt-get install python-virtualenv # on Ubuntu
create a virtual-env against the Python you want, and activate it
$> virtualenv -p /usr/bin/pythonX ve
$> source ve/bin/activate
install django into this virtual-env
$> pip install django
...
PROFIT!