Error installing Django: syntax error - python

I made a few experimentations upgrading from python 2.6.5 to python 2.7.11 in order to get Django to work properly. Then I had to uninstall python 2.7.11 and get back to python 2.6.5 (compatibility issues with other projects). Now, when I try to install django 1.2.1 using pip install django==1.2.1 I get this error:
C:\workspace\internal\trunk\ut_pr_01\src>pip install django==1.2.1
Downloading/unpacking django==1.2.1 Running setup.py egg_info for
package django
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "c:\users\maxim\appdata\local\temp\pip-build\django\setup.py", line
32, in <module>
version = __import__('django').get_version()
File "c:\users\maxim\appdata\local\temp\pip-build\django\django\__init__.py",
line 3, in <module>
from django.utils.version import get_version
File "c:\users\maxim\appdata\local\temp\pip-build\django\django\utils\version.py",
line 7, in <module>
from django.utils.lru_cache import lru_cache
File "c:\users\maxim\appdata\local\temp\pip-build\django\django\utils\lru_cache.py",
line 28
fasttypes = {int, str, frozenset, type(None)},
^
SyntaxError: invalid syntax
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "c:\users\maxim\appdata\local\temp\pip-build\django\setup.py",
line 32, in <module>
version = __import__('django').get_version()
File
"c:\users\maxim\appdata\local\temp\pip-build\django\django\__init__.py",
line 3, in <module>
from django.utils.version import get_version
File
"c:\users\maxim\appdata\local\temp\pip-build\django\django\utils\version.py",
line 7, in <module>
from django.utils.lru_cache import lru_cache
File
"c:\users\maxim\appdata\local\temp\pip-build\django\django\utils\lru_cache.py",
line 28
fasttypes = {int, str, frozenset, type(None)},
^
SyntaxError: invalid syntax
---------------------------------------- Command python setup.py egg_info failed with error code 1 in
c:\users\maxim\appdata\local\temp\pip-build\django Storing complete
log in C:\Users\Maxim\pip\pip.log
It seems like the version of python is what causing the problem but previously I installed any django with same pip and same python versions.
My environment currently:
pip 1.2.1,
python 2.6.5,
windows 10 64bit, needed django version: 1.2.1
Anyone with an idea?

You can have multiple version of Python installed on Windows (what you seem to be using) without any problems. You just have to make sure the default version of Python is set correctly for your situation.
Instead of using an extremely outdated version of django, install the latest version of Python - just choose a different path for it from the installer. So instead of C:\Python27 set it to C:\Python-27 or anything else.
If you are installing Python 3, you don't have to change the path since Python 3 installs itself in C:\Program Files (the default location for programs in Windows) and thus will not clash with Python 2 which installs directly onto the C:\ drive.
Once you have an updated version of Python installed, you just have to make sure that you call that version of Python when you need to install django. To do this effectively, use a Python virtual environment.
Lets assume you have installed the latest version of Python 2 in C:\Python-27, here is how you would install the latest version of django against it:
First, you need to install the virtualenv package. Open a command prompt and then type the following (the > is the prompt, don't type that):
> C:\Python-27\Scripts\pip.exe install virtualenv
A few minutes later you should have virtualenv installed, next step is to install django inside a new virtual environment:
> C:\Python-27\Scripts\virtualenv.exe C:\%USER%\Desktop\django-env
Once that is done, you need to activate the environment, and install django:
> C:\%USER%\Desktop\django-env\bin\activate.bat
(django-env) > pip install django
Now you have the latest version of django installed on an updated version of Python.
Managing these environments can be difficult; so I would suggest downloading a Python IDE. PyCharm is what I use and there is a free community version available. It will make it easy to manage all the different versions of Python for you.

Python 2.6 does not have set literals.
# in python 2.6 only this will work
fasttypes = set(int, str, frozenset, type(None))
# in python 2.7+ this will work as well
fasttypes = {int, str, frozenset, type(None)}
The version of Django you are using is not compatible with python 2.6.5
Support for Python 2.6 was dropped in Django 1.7, so I'm not sure why you get this error when you try to install Django 1.2.1. Maybe a more recent version is residing in the temp\pip-build\ directory. Since it's called temp it should be safe to delete that directory.
In any case, Python 2.6 and the corresponding Django versions are insecure and unsupported. I highly recommend using a current version instead. If other projects need old deprecated Python versions, you should use virtual environments to isolate them.

The problem was solved by installing the Django version I need - 1.2.1 not using pip but downloading the files and manually running:
python setup.py install .

Related

Install via pacman to specific version of Python

The default Python version for MSYS2 seems to be 3.8. I need to use 3.7 at the moment because I have to use PyInstaller and it is not currently compatible with 3.8 in MSYS2. I can download the earlier version of Python from http://repo.msys2.org/ and install it using pacman. With a fresh install of MSYS2 I run the following commands:
pacman -S glib2-devel
pacman -U python-3.7.4-1-x86_64.pkg.tar.xz
pacman -S python-pip
pacman -S python-setuptools
If I try to run a python script I am met with an error:
File "setup.py", line 15, in <module>
from setuptools import setup
ModuleNotFoundError: No module named 'setuptools'
This is due to the fact that everything installed after Python is actually installing in the default Python 3.8 location rather than 3.7:
C:\msys64\usr\lib\python3.8\site-packages
If I copy and paste the contents of site-packages into Python 3.7 and then try running a script I get the error:
File "setup.py", line 15, in <module>
from setuptools import setup
File "/usr/lib/python3.7/site-packages/setuptools/__init__.py", line 19, in <module>
from setuptools.dist import Distribution
File "/usr/lib/python3.7/site-packages/setuptools/dist.py", line 34, in <module>
from setuptools import windows_support
File "/usr/lib/python3.7/site-packages/setuptools/windows_support.py", line 2, in <module>
import ctypes
File "/usr/lib/python3.7/ctypes/__init__.py", line 7, in <module>
from _ctypes import Union, Structure, Array
ImportError: No such file or directory
Which is supposed to be resolved via libffi, which was installed prior to Python, but likely does not go to a location that 3.7 can recognize?
Is there a way to set a specific version of Python as the default in MSYS2? Perhaps a path that can be set in the .bashrc file? I tried to set PYTHONPATH in there to Python 3.7 but it didn't make a difference as to where the packages ended up being installed to.
Go to the following URL...
https://repo.msys2.org/msys/x86_64/
Look for the version of the package you need and download it. Use
pacman -U pkgname
To install it...
The reason I know this is because gcc11 on MSYS is non-functional... it produces programs which crash and say
"During startup your program exited with code..." mentioned here:
During startup program exited with code 0xc0000139
The only workaround is to downgrade to the previous compiler which does work or use clang, which was not an option for me.
Trying to use an old version of Python is probably possible, but I think it will be very difficult. You would need to make sure all the other installed packages are compatible.
I am using PyInstaller with Python 3.8 in MSYS2 without issues. I would recommend trying to work through any issues with that, instead of trying to use older versions of packages.

How can I effectively downgrade python in Linux?

I wanted to use turicreate library which doesn't support python 3.8 yet. So tried downgrading python to 3.7 using
downgrade python
But now I cant use pip. Even a simple command using pip like,
pip --version
gives me an error:
Traceback (most recent call last):
File "/usr/bin/pip", line 6, in <module>
from pkg_resources import load_entry_point
ModuleNotFoundError: No module named 'pkg_resources'
I have already tried downgrading pip to 19.0.3.
Also tried uninstalling and reinstalling both packages.
What can I possibly do? I use Arch Linux btw.
Instead of downgrading python for the whole OS, may be you should try using a downgraded python version for just your project.
Try using a virtual environment and use it to create a dev environment with python 3.7.

How do I update python on my Raspberry Pi to at least 3.6?

As some brief background information: I was origianlly trying to use Miniconda (with conda) to install dependencies that I need for my project on my Raspberry Pi. After trying to use Conda to install the SimpleAudio package, I got an error saying that it did not exist, therefore I proceeded to install this through Pip. Pip found the correct package although I get the following error message:
pi#raspberrypi:~ $ pip install simpleaudio
Traceback (most recent call last):
File "/home/pi/miniconda3/bin/pip", line 7, in <module>
from pip._internal.cli.main import main
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/cli/main.py", line 10, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
from pip._internal.cli import cmdoptions
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/cli/cmdoptions.py", line 28, in <module>
from pip._internal.models.target_python import TargetPython
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/models/target_python.py", line 4, in <module>
from pip._internal.utils.misc import normalize_version_info
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_internal/utils/misc.py", line 20, in <module>
from pip._vendor import pkg_resources
File "/home/pi/miniconda3/lib/python3.4/site-packages/pip/_vendor/pkg_resources/__init__.py", line 92, in <module>
raise RuntimeError("Python 3.5 or later is required")
RuntimeError: Python 3.5 or later is required
It seems I need to update Python, although when I print the verion on Spyder IDE, it says I am already using 3.7.
Have I caused some sort of mismatch between what version my IDE is using and what the default process the terminal uses to look up the version? I noticed that it is looking for the Python version under Miniconda. If I can update If so is there a fix for this?
Please as me for more information if required (I am fairly new to stack overflow).
UPDATE:
I have been able to install the updated version of Python to 3.6 using the following instructions:
https://stackoverflow.com/a/56852714/12361146
This generally solves the scope of this question in terms of how I update Python, but I am still confused as to why Spyder IDE uses a more up-to-date version of Python whereas the terminal shows otherwise.
To answer the question of why Spyder reports a more up-to-date version of Python, here's the reason. The default versions of Python that are installed with Raspbian are 2.7 and 3.5, located in the /usr/bin/ directory. When you install Spyder, however (either independently, or more commonly, using conda), it includes its own installation of Python, which it is configured to use in the IDE, and which is located in a different directory. Hence when you compare the versions, first by entering python3 --version on the command line, and then print(sys.executable) from the Spyder IDE, they're different.
Now the issue with using pip alongside conda for updating the Spyder installation of Python is that it has the potential to mess it up quite badly, so avoid that unless you really know what you're doing. From code you posted above, you have avoided that, though, since that will have impacted the default Raspbian installation of Python, not the Spyder one. Upgrading the latter version should be done using Conda, not pip.
Hopefully you're now all up and running.
You can install newer versions of python using the package manager apt or apt-get.
Start by getting up-to-date package definitions.
$ sudo apt-get update
Then you can show details about the python3 package.
$ apt-cache show python3
When I run that now I get "Version: 3.7.3-1".
To install the python3 package and all its dependencies.
$ sudo apt-get install python3
You will still need to type python3 and pip3 when you run the commands because you are not replacing the built-in python 2.7.
Try these commands to see what you get
$ python --version
$ python3 --version
If you want to change the default python to python3 then have a look at this answer How to change the default python version in Raspberry Pi

installing django on mavericks

I installed django using pip install django==1.5.4 and I see it in the following directory:
/usr/local/lib/python2.7/site-packages/django
however, when I type in python and then say import django, I see the following output:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named django
Is there anything else I can/need to do? I tried to uninstall and reinstall several times! I can confirm that 2.7.5 is the version of python used on my system...
EDIT
I realized now that if I type in python it defaults to Python 2.7.5. But if I type in python2 it defaults to 2.7.6.
They are installed in these locations:
/System/Library/Frameworks/Python.framework/Versions/2.7 -- 2.7.5
/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7 -- 2.7.6
Is there anyway to make the 2.7.6 version the default when I type in python? Seems like django is installed there....
I figure that you have a link /usr/bin/python that points to your 2.7.5 version, so remove it and create other with the same name (python) to the version you want to use as default.
Nevertheless I recommends you to use virtualenvwrapper.

Unable to install boto in python3

I am trying to install boto from the source code / pypi, but I am unable to install it using python 3.2. Why is it failing?
c:\boto>..\Python32\python.exe setup.py install
Traceback (most recent call last):
File "setup.py", line 35, in <module>
from boto import __version__
File "c:\boto\boto\__init__.py", line 26, in <mod
ule>
from boto.pyami.config import Config, BotoConfigLocations
File "c:\boto\boto\pyami\config.py", line 185
print s.getvalue()
^
SyntaxError: invalid syntax
print s.getvalue()
is Python 2 syntax. From the README:
If you are interested in trying out boto with Python 3.x, check out the neo branch. This is under active development and the goal is a version of boto that works in Python 2.6, 2.7, and 3.x. Not everything is working just yet but many things are and it's worth a look if you are an active Python 3.x user.
I got it working on Python 3 by installing from the develop branch as the PyPI version did not work at the time of writing. E.g. add this to your requirements.txt:
git+https://github.com/boto/boto.git#develop
Once you find a working version, it's good to freeze your dependency to a specific commit, e.g.:
git+https://github.com/boto/boto.git#5a28d1c6a3b11b979bf32ea7fbfd6d5156c01395
(ideally, of course, we wouldn't need to install from a repository in the first place :)
Update 2015 – can be installed directly from PyPI. See David's comment below.

Categories