I am using Python 3.2.3. And I installed Jinja2.5 by downloading from this page: https://pypi.python.org/pypi/Jinja2/2.5.5
Then I used the setup.py to install it. This seemed worked like a charm. When I tested it by using this line:
from jinja2 import Template
I got the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.2/dist-packages/Jinja2-2.5.5-py3.2.egg/jinja2/__init__.py", line 37, in <module>
from jinja2.environment import Environment, Template
File "/usr/local/lib/python3.2/dist-packages/Jinja2-2.5.5-py3.2.egg/jinja2/environment.py", line 13, in <module>
from jinja2 import nodes
File "/usr/local/lib/python3.2/dist-packages/Jinja2-2.5.5-py3.2.egg/jinja2/nodes.py", line 18, in <module>
from jinja2.utils import Markup, MethodType, FunctionType
File "/usr/local/lib/python3.2/dist-packages/Jinja2-2.5.5-py3.2.egg/jinja2/utils.py", line 585, in <module>
from markupsafe import Markup, escape, soft_unicode
File "/usr/local/lib/python3.2/dist-packages/markupsafe/__init__.py", line 70
def __new__(cls, base=u'', encoding=None, errors='strict'):
^
SyntaxError: invalid syntax
This is on my Raspberry pi with Raspbian installed. I don't know why this error occures, because the docs say Jinja2.5 and Python 3.2 are compatible.
Can anyone help me out?
Thanks in advance!
Try typing python --version if the reply does not say Python 3. something then your default python is python 2 and so does not support u'' for unicode strings.
If this is the case you need to install jinja2 by using pip3 install jinja2 and run your scripts with python3 scriptname.py.
Other than that see: Syntax error in jinja 2 library basically python 3.2 is no longer supported so the choice is pick another library or upgrade python.
Related
I wanted to create a virtualenv for python 2.7 (I'm using 3.7)
I run the cmd as admin (on windows 10) :
C:\WINDOWS\system32>virtualenv -p C:\Python27\python.exe py27
An I got the error:
Running virtualenv with interpreter C:\Python27\python.exe
Traceback (most recent call last):
File "c:\path\to\virtualenv.py", line 26, in <module>
import logging
File "C:\Python27\lib\logging\__init__.py", line 43, in <module>
import threading
File "C:\Python27\lib\threading.py", line 15, in <module>
from collections import deque
File "C:\Python27\lib\collections\__init__.py", line 55
raise AttributeError(f'module {__name__!r} has no attribute {name!r}')
^
SyntaxError: invalid syntax
When I Launch Python2.7 and try to import the logging module: It show the same error but When I retype it. It work just fine:
>>> import logging
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\logging\__init__.py", line 43, in <module>
import threading
File "C:\Python27\lib\threading.py", line 15, in <module>
from collections import deque
File "C:\Python27\lib\collections\__init__.py", line 55
raise AttributeError(f'module {__name__!r} has no attribute {name!r}')
^
SyntaxError: invalid syntax
>>> import logging
>>> logging.warning('hello word')
WARNING:root:hello word
>>>
I can't figure out why it does that.
I have already configured a virtual env with python 3.6
Any help would be appreciated.
You have a version problem. This line
raise AttributeError(f'module {__name__!r} has no attribute {name!r}')
is being run under Python 2.7, but is Python 3.6 (or 3.7) and will give you a syntax error in earlier versions. In your case I would treat that Python 2.7 installation as irretrievably broken, because it is clear that the standard library isn't to be trusted to all be of a consistent version.
The problem was resolved deleting the c:\Python27 directory, Then Uninstalling python 2.7 using the setup tool, restarting the computer and reinstalling Python 2.7
Smartsheet API beginner using python is in need of help
Hi, everyone. I am working on smartsheet API and am trying to follow the website to get some exercise first from https://smartsheet-platform.github.io/api-docs/#sdks-and-sample-code.
I have python 2.7.15 on Mac, so the first step I did was to download the pip folder, and type "pip install smartsheet-python-sdk" on my terminal to install pip. Then I used my .py file to test out the code, I ran the first line import smartsheet and there is an error already.
The message I got is below, any suggestions will be appreciated:
Traceback (most recent call last):
File "/Users/my name /Desktop/charity.py", line 6, in <module>
import smartsheet
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/smartsheet/__init__.py", line 31, in <module>
from .smartsheet import Smartsheet, fresh_operation, AbstractUserCalcBackoff # NOQA
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/smartsheet/smartsheet.py", line 34, in <module>
from .models import Error, ErrorResult
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/smartsheet/models/__init__.py", line 21, in <module>
from .access_token import AccessToken
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/smartsheet/models/access_token.py", line 20, in <module>
from ..types import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/smartsheet/types.py", line 26, in <module>
from enum import Enum
ImportError: No module named enum
enum module was added in Python 3.4 but you're on Python 2.7. The smartsheet platform claims to support Python 2.7 but it also requires the import of enum for it to work.
You can submit an issue to the project and hope that they fix it or upgrade to Python 3.4 and beyond.
Per a previous answer, the error is due to using Python 2, while enum was added in Python 3.4. However, there is a backport if you need to use Python 2 for some reason.
Simply install with pip install enum34. I tested smartsheet with the enum34 library using Python 2.7.16 and was successful.
A have a problem where try to install module from pip like:
Install packages failed: Error occurred when installing package lxml.
The following command was executed:
packaging_tool.py install --build-dir C:\Users\User\AppData\Local\Temp\pycharm-packaging2629877941665473195.tmp lxml
The error output of the command:
C:\Python32\lib\site-packages\pip\_vendor\pkg_resources\__init__.py:87: UserWarning: Support for Python 3.0-3.2 has been dropped. Future versions will fail here.
warnings.warn(msg)
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 3.1\helpers\packaging_tool.py", line 125, in main
retcode = do_install(pkgs)
File "C:\Program Files (x86)\JetBrains\PyCharm 3.1\helpers\packaging_tool.py", line 56, in do_install
import pip
File "C:\Python32\lib\site-packages\pip\__init__.py", line 16, in <module>
from pip.vcs import git, mercurial, subversion, bazaar # noqa
File "C:\Python32\lib\site-packages\pip\vcs\mercurial.py", line 9, in <module>
from pip.download import path_to_url
File "C:\Python32\lib\site-packages\pip\download.py", line 36, in <module>
from pip.utils.ui import DownloadProgressBar, DownloadProgressSpinner
File "C:\Python32\lib\site-packages\pip\utils\ui.py", line 15, in <module>
from pip._vendor.progress.bar import Bar, IncrementalBar
File "C:\Python32\lib\site-packages\pip\_vendor\progress\bar.py", line 48
empty_fill = u'\u2219'
^
SyntaxError: invalid syntax
How fix this? I can not install any module or rollback pip.
Python 3.2
Pip 8.1.1
You need to upgrade your Python. Python 3.2 does not support Unicode string literals with the u"..." syntax (the idea was that these are not needed anymore because all string literals are Unicode in Python 3.x). This is why you are getting the error.
In Python 3.3, this feature was restored to make it easier to write code that runs on either Python 2.x or 3.x and clearly PIP is taking advantage of this.
Indeed, the documentation for PIP 8.1.1 mentions that it needs Python 3.3 or later.
My issue is possibly similar to link
but thought I'd ask jic. I'm on osx and trying to use jedi-vim. I installed jedi using pip and then jedi-vim by cloning into the dir that my vim config uses for loading packages. this one for reference. When I start vim with a python program I get the "Please install Jedi if..." message. I cloned vim 74 and configured with +python and +conceal. After still getting the error I looked into the code and found it was an import error.
As an aside, this isn't the best help message. Better might be "Unable to import jedi. Have you installed Jedi?"
I tried import jedi from within vim, as :python import jedi
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/jedi-0.9.0- py2.7.egg/jedi/__init__.py", line 41, in <module>
from jedi.api import Script, Interpreter, NotFoundError, set_debug_function
File "/usr/local/lib/python2.7/site-packages/jedi-0.9.0 py2.7.egg/jedi/api/__init__.py", line 16, in <module>
from jedi.parser import Parser, load_grammar
File "/usr/local/lib/python2.7/site-packages/jedi-0.9.0-py2.7.egg/jedi/parser/__init__.py", line 21, in <module>
from jedi.parser import tree as pt
ImportError: cannot import name tree
If this is a build issue, is there a good reference for building vim on mac?
I have installed protobuf in Python 3.4 and i pushed the compiled code pb_x_pb2.py into python34 folder. When i enter import pb_x_pb2.py it shows the following error.
>>> import pb_interface_pb2
Traceback (most recent call last):
File "<pyshell#21>", line 1, in <module>
import pb_interface_pb2
File "C:\Python34\pb_interface_pb2.py", line 5, in <module>
from google.protobuf import reflection
File "C:\Python34\lib\site-packages\google\protobuf\reflection.py", line 68, in <module>
from google.protobuf.internal import python_message
File "C:\Python34\lib\site-packages\google\protobuf\internal\python_message.py", line 848
except struct.error, e:
^
SyntaxError: invalid syntax
Protobuf doesn't really support python 3.x. For the imported libraries, try pip install protobuf-py3, a python 3 port of the package. You can also run the 2to3.py script from the Pythonxx\Tools\Scripts folder on the generated file.
Another option would be to download the newest version of the sources, and compile them yourself. I believe that the newest version is mostly compatible with both 2.x and 3.x