简体   繁体   中英

Installing Django on Ubuntu 16.04, python3

I am unable to install django on python3 in ubuntu 16.04. Here is what I have tried:

1. pip3 install django
2. pip3 install --trusted-host pypi.python.org django
3. pip3 install --index-url=http://pypi.python.org/simple --trusted-host pypi.python.org django

I keep getting the same error:

Could not fetch URL https://pypi.python.org/simple/django/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
Could not find a version that satisfies the requirement django (from versions: )
No matching distribution found for django

I have Django installed on python 2.7, but I need it on python 3.6.

When I run

sudo apt-get install python3-django

it says

python3-django is already the newest version (1.8.7-1ubuntu5.5).

I believe this is because I have python3.5 installed with Django on python3.5, but I need it on 3.6. Python3 refers python3.6. My pip3 is up to date.

Any help is appreciated.

1st : You didn't explicitly say so, but I am assuming you are using linux based on your mention of apt-get

The simplest way to get django on your python 3.6 is to fix pip. This is a pretty good overview of how to get the libraries that pip needs based on error messages such as yours. You just need to apt install a few packages.

Once you have all the dependencies installed for pip3 to run, try installing django again.
Note : since you have python3 already, I'd make sure you are calling the right pip3, you can do this by calling:

pip3 -V

If the 'pip3' command is calling the pip3 in 3.5, then use the full path of the pip3 in python 3.6 instead.

Alternatively

You can try copying django from your lib/site-packages folder from your python3.5 installation to your python3.6 installation. The big gotcha is that you need to make sure to copy all the dependencies for django as well. You can ether look them up in the django config or you can try and use it and copy them over one at a time based on the error messages.

Unsolicited Advice : I would strongly suggest using virtualenvs to make this process much easier. I use pyenv and pyenv-virtualenv here , and have really loved them.

16.04 is a LTS release. As such it is locked to python 3.5. You may have noticed that there were no packages in the Xenial repositories and had to install python 3.6 from alternate sources. Just be careful with that since things can break at the system level. In the end I went with building python from source and generating a django venv using.

python3.6 -m venv mydjangoproject

See this post for more details.

See this gist for a working Ubuntu16.04 Python 3.6.3 example

#allow to add latest python version-

sudo add-apt-repository ppa:deadsnakes/ppa

#update-

sudo apt update

#installing python3.6 and pip package manager-

sudo apt install python3.6 python3-pip

                                                     

#update for alternative version of python-

sudo update-alternatives --install /usr/bin/python3 python3/usr/bin/python3.6 1 

          

#configuring python 3.6-

sudo update-alternatives --config python3  

#install django -

sudo apt install python3-django 

                                                                

#adding project name-

django-admin startproject projectname 

                                                                         

#cd to project dir-

cd projectname        

                                                                         
                                                                                                            

#add your ip add using vim or any editor in settings.py inside []-

nano ~/projectname/projectname/settings.py   

#Run the server-

python3 manage.py runserver 0.0.0.0:8000

                                                      
                                                                     

#run at browser using 127.0.0.1:8000

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM