Syntax Error When Running paster? - python

No idea what happened, but all of a sudden, paster stopped working on my server (working with virtualenv and pyramid). Tried reinstalling everything but didn't work - same error again:
Traceback (most recent call last):
File "bin/paster", line 7, in ?
sys.exit(
File "/home/user/webapps/myapp/htdocs/lib/python2.4/site-packages/PasteScript-1.7.3-py2.4.egg/paste/script/command.py", line 83, in run
command = commands[command_name].load()
File "/home/user/webapps/myapp/htdocs/lib/python2.4/site-packages/setuptools-0.6c11-py2.4.egg/pkg_resources.py", line 1954, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/home/user/webapps/myapp/htdocs/lib/python2.4/site-packages/PasteScript-1.7.3-py2.4.egg/paste/script/serve.py", line 19, in ?
from paste.deploy import loadapp, loadserver
File "/home/user/webapps/myapp/htdocs/lib/python2.4/site-packages/PasteDeploy-1.5.0-py2.4.egg/paste/deploy/__init__.py", line 3, in ?
from paste.deploy.loadwsgi import *
File "/home/user/webapps/myapp/htdocs/lib/python2.4/site-packages/PasteDeploy-1.5.0-py2.4.egg/paste/deploy/loadwsgi.py", line 393
with open(filename) as f:
^
SyntaxError: invalid syntax
What is happening to me?

You are using Python 2.4. It does not have the with statement. It only came in Python 2.5.
Update your version of Python.

Related

Py to exe pyinstaller import errors

Im trying to convert a single file python script/project into an exe using pyinstaller
Even thought pyinstaller converts the script the .exe will run and throw this
Traceback (most recent call last):
File "main.py", line 4, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
File "pynput\__init__.py", line 40, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
File "pynput\keyboard\__init__.py", line 31, in <module>
File "pynput\_util\__init__.py", line 76, in backend
ImportError
[16676] Failed to execute script main
I'm stumped , through my trial and erroring i figured that when i replace pynput with a module like random the convertion works fine , but i need it to work with pynput
please help , thanks in advance!
Authors made some changes which i feel broke the reference.
so instead of package it is referring file.
- backend = backend(__package__)
+ backend = backend(__name__)
pls try to downgrade your package and check that your app still works.
pip install pynput==1.6.8
then your command like following would work.
pyinstaller --onefile build_pkg_for.py

Spyder (Anaconda) Not Running because of some errors

When I am trying to run the spyder (Anaconda) I am getting the following Error:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\Scripts\spyder-script.py", line 10, in
sys.exit(main())
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\app\start.py", line 205, in main
mainwindow.main()
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 3651, in main
mainwindow = run_spyder(app, options, args)
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 3526, in run_spyder
main.setup()
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 945, in setup
from spyder.plugins.ipythonconsole.plugin import IPythonConsole
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\ipythonconsole\plugin.py", line 46, in
from spyder.plugins.ipythonconsole.widgets import (ClientWidget,
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\ipythonconsole\widgets\__init__.py", line 16, in
from .debugging import DebuggingWidget
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\ipythonconsole\widgets\debugging.py", line 13, in
import pdb
File "C:\ProgramData\Anaconda3\lib\pdb.py", line 138, in
class Pdb(bdb.Bdb, cmd.Cmd):
AttributeError: module 'cmd' has no attribute 'Cmd'
Can someone please health me to resolve this issue?
I have created a file with the name cmd.py. After deleting the file (or rename the file), my problem got solved.
Do you happen to have a file named cmd.py in the same directory as the file you are trying to execute?
Cause If you are, then import cmd would not import the right python module. Instead, it would import your created "cmd.py" file.
I too faced this issue cause I had a file named "cmd.py" along with my python scripts and it would import that whenever I said import cmd. Renaming it helped me solve the issue

get-pip.py script not running.i am using python 3.2.1.getting the error. i have tried repairing,uninstall/reinstalling everything

here is the error message i am getting while running the script on IDLE.i have downloaded the get-pip.py file from the pypi.org.
Traceback (most recent call last):
File "C:\Users\hp1\Desktop\get-pip.py", line 20649, in <module>
main()
File "C:\Users\hp1\Desktop\get-pip.py", line 197, in main
bootstrap(tmpdir=tmpdir)
File "C:\Users\hp1\Desktop\get-pip.py", line 82, in bootstrap
import pip._internal
File "c:\users\hp1\appdata\local\temp\tmpjlf6u8\pip.zip\pip\_internal\__init__.py", line 42, in <module>
File "c:\users\hp1\appdata\local\temp\tmpjlf6u8\pip.zip\pip\_internal\cmdoptions.py", line 16, in <module>
File "c:\users\hp1\appdata\local\temp\tmpjlf6u8\pip.zip\pip\_internal\index.py", line 15, in <module>
File "c:\users\hp1\appdata\local\temp\tmpjlf6u8\pip.zip\pip\_vendor\requests\__init__.py", line 83, in <module>
File "c:\users\hp1\appdata\local\temp\tmpjlf6u8\pip.zip\pip\_internal\compat.py", line 61
return u"".join(u"\\x%x" % c for c in raw_bytes), err.end
^
SyntaxError: invalid syntax
You must read prerequisites before running this script. It is a tool by PyPA, not pypi.org. So you must follow this link: pip Installation
Another thing is it works with these versions (2.7, 3.3, 3.4, 3.5, 3.6) of python according to official documentation.

Issue creating project with mezzanine - shared hosting

I'm trying to use Mezzanine cms in a shared hosting at 1and1. I installed a recent python version 3.3.2.
setup works well but when i try to create a project I got the following error message:
~/Mezzanine-1.4.16 > mezzanine-project blog
Traceback (most recent call last):
File "/kunden/homepages/x/dxxxxxxx/htdocs/custom/bin/mezzanine-project", line 9, in
load_entry_point('Mezzanine==1.4.16', 'console_scripts', 'mezzanine-project')()
File "/kunden/homepages/x/dxxxxxxx/htdocs/custom/lib/python3.3/site-packages/distribute-0.6.49-py3.3.egg/pkg_resources.py", line 345, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/kunden/homepages/x/dxxxxxxx/htdocs/custom/lib/python3.3/site-packages/distribute-0.6.49-py3.3.egg/pkg_resources.py", line 2382, in load_entry_point
return ep.load()
File "/kunden/homepages/x/dxxxxxxx/htdocs/custom/lib/python3.3/site-packages/distribute-0.6.49-py3.3.egg/pkg_resources.py", line 2088, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/kunden/homepages/x/dxxxxxxx/htdocs/custom/lib/python3.3/site-packages/Mezzanine-1.4.16-py3.3.egg/mezzanine/bin/mezzanine_project.py", line 9, in
from mezzanine.utils.importing import path_for_import
File "/kunden/homepages/x/dxxxxxxx/htdocs/custom/lib/python3.3/site-packages/Mezzanine-1.4.16-py3.3.egg/mezzanine/utils/importing.py", line 23
except (ValueError, ImportError, AttributeError), e:
^
SyntaxError: invalid syntax
Any thoughts on how to fix this ? thank you.
Current version of Mezzanine (1.4.16) doesn’t support Python 3. You have to use Python 2.6 / 2.7 (Source: dependencies section in official docs).
Now supporting with Mezzanine 3.x

Django-admin.py producing errors on my shared hosting environment

I tried to install django on my shared hosting environment, which has SSH access.
I downloaded the newest version of Django using
svn export http://code.djangoproject.com/svn/django/trunk/django django
I can import Django in python shell without any error throwing.
But then I tried to start a new project using django-admin.py and it started throwing me a bunch of error, in which I tried to google for the past few hours. I still can't find it
Below is the actual error:
k4660061#server42222:~$ django-admin.py startproject klikevent
/u/k4660061/home/local/lib/python/site-packages/django/core/management/templates.py:155: Warning: 'with' will become a reserved keyword in Python 2.6
Traceback (most recent call last):
File "/u/k4660061/home/local/lib/python/site-packages/django/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/u/k4660061/home/local/lib/python/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
utility.execute()
File "/u/k4660061/home/local/lib/python/site-packages/django/core/management/__init__.py", line 381, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/u/k4660061/home/local/lib/python/site-packages/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/u/k4660061/home/local/lib/python/site-packages/django/core/management/__init__.py", line 69, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/u/k4660061/home/local/lib/python/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/u/k4660061/home/local/lib/python/site-packages/django/core/management/commands/startproject.py", line 2, in <module>
from django.core.management.templates import TemplateCommand
File "/u/k4660061/home/local/lib/python/site-packages/django/core/management/templates.py", line 155
with open(old_path, 'r') as template_file:
^
SyntaxError: invalid syntax
k4660061#server42222:~$
Thanks
UPDATE
After a good night sleep, I got it working! See answer by Bernie. I have to see the stacktrace over and over, but I just need to add the import statement to multiple file
the file are
django/utils/archive.py
django/core/management/templates.py
and any file that throw the warning with_statement
Thanks #Bernie
If the syntax error is related to the with statement, it could be that your prod server has an older version of Python than your dev server.
If your prod server is running version 2.5 or higher you can do this:
from __future__ import with_statement
Please note: any from __future__ imports must be the very first import.
Reference: http://docs.python.org/reference/simple_stmts.html#future

Categories

Resources