Installing Django on Ubuntu 16.04, python3

2019-08-21 05:30发布

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.

2条回答
别忘想泡老子
2楼-- · 2019-08-21 06:04

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

查看更多
We Are One
3楼-- · 2019-08-21 06:09

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.

查看更多
登录 后发表回答