According to Django 2.0 release notes Django 2.0 onwards will only support python 3, making the 1.11.X the last release series to support python 2.
See quote from the release notes page:
Django 2.0 supports Python 3.4, 3.5, and 3.6. We highly recommend and only officially support the latest release of each series.
The Django 1.11.x series is the last to support Python 2.7.
However when running pip2 install Django, django version 2 is being installed (which then fails because it assumes functionality not available in python 2):
(venv-crap) mbp15:server nir$ pip2 install django
Collecting django
Downloading Django-2.0.tar.gz (8.0MB)
100% |████████████████████████████████| 8.0MB 177kB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/PATH/django/setup.py", line 32, in <module>
version = __import__('django').get_version()
File "django/__init__.py", line 1, in <module>
from django.utils.version import get_version
File "django/utils/version.py", line 61, in <module>
#functools.lru_cache()
AttributeError: 'module' object has no attribute 'lru_cache'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/PATH/django/
I know I can manually specify requirement version below 2, making pip install a version valid for python 2, however that will complicate the installation process if I want to support both python2 and python3, and would have assumed pip will know to install only versions compatible with the python it's running from.
My questions, therefore, as the following:
Why is pip attempting to install Django2 with python2 instead of automatically picking the last compatible version? Isn't that part of pips capabilities?
Is there a way to make a single requirements.txt that will install Django<2.0 when running from python2 and Django>=2.0 when running with python3?
Why is pip attempting to install Django2 with python2 instead of automatically picking the last compatible version? Isn't that part of pips capabilities?
As Alasdair pointed out in the comments already, this is a known bug in Django: bug #28878.
Is there a way to make a single requirements.txt that will install Django<2.0 when running from python2 and Django>=2.0 when running with python3?
You can use the environment markers (see PEP 508):
# requirements.txt
django>=1.11,<2.0; python_version<"3.4"
django>=2.0; python_version>="3.4"
This will install one and skip another django dependency, depending on what python you are using:
$ pip2.7 install -r requirements.txt
Ignoring django: markers 'python_version >= "3.4"' don't match your environment
Collecting django<2.0 (from -r requirements.txt (line 1))
Downloading Django-1.11.8-py2.py3-none-any.whl (6.9MB)
...
$ pip3.6 install -r requirements.txt
Ignoring django: markers 'python_version < "3.4"' don't match your environment
Collecting django>=2.0 (from -r requirements.txt (line 2))
Using cached Django-2.0-py3-none-any.whl
...
Related
I am trying to install pre-commit for python2.7 with pip 8.1.2.
If i do pip install --user pre-commit or ´python -m pip install --user pre-commit´ it keeps trying to load pre-commit3.0.2 and failing.
So i tried to find the most recent version that still supports python2.7 (by manually going through the version history, is there not better way?) and that is 1.21.0.
But even when i do pip install --user pre-commit==1.21.0 it fails due to
Collecting virtualenv>=15.2 (from pre-commit==1.21.0)
Using cached https://files.pythonhosted.org/packages/7b/19/65f13cff26c8cc11fdfcb0499cd8f13388dd7b35a79a376755f152b42d86/virtualenv-20.17.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-mjJnKQ/virtualenv/setup.py", line 4, in <module>
raise RuntimeError("setuptools >= 41 required to build")
RuntimeError: setuptools >= 41 required to build
which i assume is because virtualenv-20.17.1 requires python3
Yes, I think pre-commit is not supported for Python 2.7 and starts only in 3.7 but you can write a custom hook or any other tools that you are using for linting based on the IDE you are using.The hook would need to check for any errors in the code before committing, and if any errors are found, it should fail the commit and display a warning message.
As the title says, I am trying to install a program that has a couple of dependecies that demand a specific Python version (>= 3.7). I do not have admin rights, so I can't use sudo. The Python version installed is 2.7. Because of that, I used virtualenv to install and execute Python 3.9.5.
I executed venv, and checked the Python and pip versions:
which python
/home/honda/venv_python-3.9.5/bin/python
which pip
/home/honda/venv_python-3.9.5/bin/pip
I even checked the version using:
python
Python 3.9.5 (default, May 10 2021, 13:50:25)
Which, as I understand, means that I have the correct Python/pip versions.
However, when I try to install the program, I get this:
./install.sh ../Programs/
Installing darwin binary...
Installing oma...
Installing libraries...
creating virtualenv for hog_bottom_up
Collecting numpy (from -r ../Programs//OMA/OMA.2.4.2/hog_bottom_up/requirements.txt (line 1))
Using cached https://files.pythonhosted.org/packages/f3/1f/fe9459e39335e7d0e372b5e5dcd60f4381d3d1b42f0b9c8222102ff29ded/numpy-1.20.3.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-3_2_atp3/numpy/setup.py", line 30, in <module>
raise RuntimeError("Python version >= 3.7 required.")
RuntimeError: Python version >= 3.7 required.
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-3_2_atp3/numpy/
You are using pip version 8.1.1, however version 21.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Cannot install python dependencies for hog-bottom-up inference algorithm
cannot create virtual environment for hog_bottom_up
To be honest, I don't know what is happening here. Is there something I am missing? I am not experienced in using virtualenv (I previously used another computer, one that I could use sudo, so I never had any problems like this, and I did install this same program there.)
Is there anything I can try? I guess could reach out to the admin and ask them to install the program for me, but I'd rather not do that yet.
Thank you!
I am trying to write some script which requires ropper. (install only via pip)
How can i fix this problem?
I am trying to install it on linux, tried to upgrade setuptools, install old version and followed this, only one topic, which i found:
the link!
This is the error message:
$ pip install ropper
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
Collecting ropper
Using cached https://files.pythonhosted.org/packages/94/b1/922dfab5083ff439ce70358c7f3e49185c54e6ea6ee2bb7cd292e63eac06/ropper-1.12.1.tar.gz
Collecting filebytes>=0.9.18 (from ropper)
Using cached https://files.pythonhosted.org/packages/0b/3a/9fc0c62bd74583137a8bbc3c8020d6a8234b9cf8bc1e99fe929688b19093/filebytes-0.9.20.tar.gz
ERROR: Complete output from command python setup.py egg_info:
ERROR: Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-d44HeD/filebytes/setup.py", line 3, in <module>
from pathlib import Path
ImportError: No module named pathlib
----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-d44HeD/filebytes/
filebytes==0.9.20 release is not compatible with Python 2; the package maintainer already fixed this, but the new version is not yet uploaded to PyPI. Restrict filebytes to previous version for now:
$ pip install "filebytes<0.9.20" ropper
Once next version (0.9.21) is released, you can update it if you want:
$ pip install --upgrade "filebytes>0.9.20"
homebrew has again broken python for about third time. Im now having issues getting dependencies to work again. At this point I am unable to install yaml.
Collecting yaml
Could not find a version that satisfies the requirement yaml (from versions: )
No matching distribution found for yaml
Some other suggestions have said to try pyaml, which again simply tries to import yaml and fails
Traceback (most recent call last):
File "script.py", line 13, in <module>
import pyaml
File "/~/virtualenv/project/lib/python2.7/site-packages/pyaml/__init__.py", line 6, in <module>
import os, sys, io, yaml
ImportError: No module named yaml
Anyone have an idea how to get this sorted out?
There are two packages with somewhat unfortunate naming in the Python Package Index.
pip install pyyaml lets you import yaml. This package enables Python to parse YAML files.
pip install pyaml lets you import pyaml. This package allows pretty-printing of YAML files from Python, among other things. It requires pyyaml to be installed.
So the way forward for you is:
Install pyyaml, preferably using pip
Install pyaml
Profit
Step 0 would be to run everything from a virtual environment to prevent homebrew from messing with your Python ever again. This option also lets you run multiple versions of Python, not just the one required by homebrew.
The solution for me turned out to be homebrew changing python to python2, which I believe precludes using the brew version instead of the system version
eg python script.py >> python2 script.py
Additionally, linking the system version of python to the brew python2 version helped as well:
cd /usr/local/bin && ln -s ../Cellar/python/2.7.13_1/bin/python2 python
I'm also hesitant the accepted answer will work, as pyaml is still attempting to import yaml, via __init__.py; which does not exist even after installing both packages
$ pip install pyaml
Collecting pyaml
Using cached pyaml-17.7.2-py2.py3-none-any.whl
Requirement already satisfied: PyYAML in ~/Library/Python/2.7/lib/python/site-packages (from pyaml)
Installing collected packages: pyaml
Successfully installed pyaml-17.7.2
$ pip install yaml
Collecting yaml
Could not find a version that satisfies the requirement yaml (from versions: )
No matching distribution found for yaml
eg
File "/~/virtualenv/project/lib/python2.7/site-packages/pyaml/__init__.py", line 6, in <module>
import os, sys, io, yaml
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