I'm new to github and I'm trying to install unicodecsv (https://github.com/jdunck/python-unicodecsv).
I'm trying
sudo pip install -e git://github.com/jdunck/python-unicodecsv.git#egg=unicodecsv
But I'm getting an error message. I'm probably doing someone basic wrong, can someone help?
Obtaining unicodecsv from git+git://github.com/jdunck/python-unicodecsv.git#egg=unicodecsv
Cloning git://github.com/jdunck/python-unicodecsv.git to ./src/unicodecsv
Running setup.py egg_info for package unicodecsv
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "/Users/dave/Dropbox/Promoter/working/src/unicodecsv/setup.py", line 5, in <module>
version = __import__('unicodecsv').__version__
File "unicodecsv/__init__.py", line 49
except TypeError, e:
^
SyntaxError: invalid syntax
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "/Users/dave/Dropbox/Promoter/working/src/unicodecsv/setup.py", line 5, in <module>
version = __import__('unicodecsv').__version__
File "unicodecsv/__init__.py", line 49
except TypeError, e:
^
SyntaxError: invalid syntax
----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /Users/dave/.pip/pip.log
Davids-MacBook-Air:working dave$ sudo pip install -e git://github.com/jdunck/python-unicodecsv.git#egg=unicodecsv
Obtaining unicodecsv from git+git://github.com/jdunck/python-unicodecsv.git#egg=unicodecsv
Updating ./src/unicodecsv clone
^[ Running setup.py egg_info for package unicodecsv
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "/Users/dave/Dropbox/Promoter/working/src/unicodecsv/setup.py", line 5, in <module>
version = __import__('unicodecsv').__version__
File "unicodecsv/__init__.py", line 49
except TypeError, e:
^
SyntaxError: invalid syntax
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "/Users/dave/Dropbox/Promoter/working/src/unicodecsv/setup.py", line 5, in <module>
version = __import__('unicodecsv').__version__
File "unicodecsv/__init__.py", line 49
except TypeError, e:
^
SyntaxError: invalid syntax
----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in /Users/dave/.pip/pip.log
The problem is that you're using Python 3.0 or later, and trying to use a library which is only compatible with 2.7 and earlier.
The specific problem is the line the traceback points at:
except TypeError, e:
This syntax was deprecated in 2.6, in favor of (more flexible and more consistent) new syntax:
except TypeError as e:
In 3.0 and later, the deprecated syntax is no longer allowed at all.
So, if you want to use this library, someone will have to port it—you, the author, or someone else. It may just be a matter of running 2to3, or fixing each except statement manually—but it may be a lot more to do than that, especially considering this library is all about Unicode.
However, it's worth noting that Python 3.x doesn't have the same problem as 2.x did. You can pass the csv module text/Unicode file objects, and it will just handle them. Adapting the example from the unicodecsv docs:
>>> import csv
>>> from io import StringIO
>>> f = StringIO()
>>> w = csv.writer(f)
>>> w.writerow(('é', 'ñ'))
>>> f.seek(0)
>>> r = csv.reader(f)
>>> row = r.next()
>>> print row[0], row[1]
é ñ
Note that I didn't even have to specify utf-8, because StringIO is a Unicode str buffer, not a bytes buffer. You don't have to worry about coding at all.
If you didn't even know you were running Python 3.x (as in, you knew you installed it, but you were careful to keep Apple's pre-installed Python 2.7 higher on the PATH), there are three common reasons this can happen.
Apple's Python doesn't come with pip; all of the popular Python 3.x installers and packages do. So, if you haven't installed pip for 2.7, the only one you have is 3.x.
Apple's Python installs scripts like pip to /usr/local/bin. So do some of the popular Python 3.x installers and packages. So, whichever you installed more recently wins. (The 3.x one should also be available as /usr/local/bin/pip3, so overwriting its /usr/local/bin/pip with 2.7's is usually fine… unless pip3 is a symlink to pip.)
sudo deliberately discards most of your user environment, so 2.7 may be higher on your PATH when running as yourself, but not when running with sudo.
Related
I installed pyAudioAnalysis on python2.7 using pycharm (linux). Trying to run audioBasicIO.py gives the following error. I have installed eyeD3 but it does not work.
/usr/bin/python2.7 /usr/local/lib/python2.7/dist-packages/pyAudioAnalysis/audioBasicIO.py
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/pyAudioAnalysis/audioBasicIO.py", line 6, in <module>
import eyed3
File "/home/.local/lib/python2.7/site-packages/eyed3/__init__.py", line 31, in <module>
from .utils.log import log # noqa: E402
File "/home/.local/lib/python2.7/site-packages/eyed3/utils/__init__.py", line 361
msg = f"invalid level choice: {level} (choose from {parser.log_levels})"
^
SyntaxError: invalid syntax
Is my installation incorrect? This is the first time I use this library, does anyone have any suggestions.
f-strings aren't supported for python 2.7. You need python 3.6 or above to use them. Here is a good workaround, in which you can use f-strings in below python 3.6.
I followed the procedure given on the Pelican website by:
Creating a virtualenv and then source bin/activate
Installing pelican using pip install pelican
Writing pelican-quickstart
When I typed in pelican-quickstart, I got the following error:
Traceback (most recent call last):
File "/home/ashutosh_mishra/virtualenvs/pelican/bin/pelican-quickstart", line 7, in <module>
from pelican.tools.pelican_quickstart import main
File "/home/ashutosh_mishra/virtualenvs/pelican/lib/python3.2/site-packages/pelican/__init__.py", line 19, in <module>
from pelican.generators import (ArticlesGenerator, PagesGenerator,
File "/home/ashutosh_mishra/virtualenvs/pelican/lib/python3.2/site-packages/pelican/generators.py", line 14, in <module>
from jinja2 import (BaseLoader, ChoiceLoader, Environment, FileSystemLoader,
File "/home/ashutosh_mishra/virtualenvs/pelican/lib/python3.2/site-packages/jinja2/__init__.py", line 33, in <module>
from jinja2.environment import Environment, Template
File "/home/ashutosh_mishra/virtualenvs/pelican/lib/python3.2/site-packages/jinja2/environment.py", line 677
u'\xff\xff\xff\xff'.encode('iso-8859-15')
^
SyntaxError: invalid syntax
I googled the error and found Pelican 3.3 pelican-quickstart error "ValueError: unknown locale: UTF-8"', but this doesn't solve my problem.
Can anyone suggest a solution?
While the error traceback points to an issue with Jinja2 and not Pelican directly, the most likely cause is Python 3.2 — that version of Python is rather old and is no longer supported by either the Jinja2 or Pelican development teams.
Upgrading your operating system may allow your package manager to install a more recent Python version (3.4+ recommended). Alternatively, you can use a tool such as PyEnv to install the latest version of Python without having to upgrade your operating system.
I can't seem to get python ldap libraries to work properly with Django:
>>> from django_auth_ldap import *
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named django_auth_ldap
I'm running Ubuntu v14.
This is what a pip freeze looks like on my working environment:
Django==1.9.4
django-auth-ldap==1.2.7
django-filter==0.13.0
djangorestframework==3.3.3
Markdown==2.6.5
pyasn1==0.1.9
pyldap==2.4.25.1
python3-ldap==0.9.8.4
(I installed ldap for python3 as well to do a sanity check)
But as I go through all the guides here, they all seem to point to the same libraries I already have except for "pip install python-ldap".
When I try to do:
pip install python-ldap
I just get the following result:
Collecting python-ldap
Using cached python-ldap-2.4.25.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-0c5p7fkj/python-ldap/setup.py", line 53
print name + ': ' + cfg.get('_ldap', name)
^
SyntaxError: invalid syntax
----------------------------------------
Does anyone know what are the best steps I should take to get around this issue to get the library working?
I've tried doing a wget for
https://pypi.python.org/pypi/python-ldap
And I extracted the files and simply used
python setup.py install to the tar ball, but to no avail.
Any suggestions?
Found the solution from this page:
https://www.howtoinstall.co/en/ubuntu/precise/universe/python-django-auth-ldap/
The following command seems to have done the trick:
apt-get install python-django-auth-ldap
I'm trying to install setuptools 0.9.7 with Python 3.3. I try to run "python setup.py", and also "python setup.py install" from a cmd window in a directory separate from my default python dir, and get back:
Traceback (most recent call last):
File "setup.py", line 5 in ?
import textwrap
ImportError: No module named textwrap
...even though I checked \Lib\ and textwrap.py is there. So then I copied textwrap.py to the directory I was trying to install setuptools from, and then get:
Traceback
File "setup.py", line 5, in ?
import textwrap
File "textwrap.py", line 404
yield (prefix + line if predicate(line) else line)
SyntaxError
...even though I can import textwrap.py just fine while working in the default Python directory. So I'm at a loss. I should say that I've tried to install two other modules and have received similar import errors, I was hoping setuptools would fix that. Any ideas?
Getting this error when running pip install -U selenium. Mid way through the script, it gets the following SyntaxError:
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "C:\Python32\Scripts\build\rdflib\setup.py", line 6, in <module>
from rdflib import __version__
File "rdflib\__init__.py", line 64, in <module>
from rdflib.term import URIRef, BNode, Literal, Variable
File "rdflib\term.py", line 367
except TypeError, te:
^
SyntaxError: invalid syntax
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 14, in <module>
File "C:\Python32\Scripts\build\rdflib\setup.py", line 6, in <module>
from rdflib import __version__
File "rdflib\__init__.py", line 64, in <module>
from rdflib.term import URIRef, BNode, Literal, Variable
File "rdflib\term.py", line 367
except TypeError, te:
^
SyntaxError: invalid syntax
----------------------------------------
Command python setup.py egg_info failed with error code 1
Since it is a Syntax Error, I assume it is a python version problem, I'm running 3.2.2.
Pip did come with a pip-3.2.exe file, which I tried to run. But I got the same error. I'm pretty new to Python so it might be something simple.
And how can it be a syntaxError? pip is an already made program.
Running Win7, Python 3.2.2
Selenium does not support Python 3. Use Python 2.7 instead.
Sadly, almost all Python software requires Python 2.x.
[Update]
Selenium supports Python 3.x now.