I'd wish to compile my program wrote in Python 3.2 with Pygame 1.9.5. But I'm a beginner with cx_Freeze and I've no idea how to manage with the complex structure... I mean :
My folder is like that :
gamefolder:
lib:
Menu.py (lauch the program)
level.py
othermodules.py
...
data:
Level1.png
otherspictures.png
So I tried to compile but I always get an error when I lauch Main.exe, indeed I think pygame is not load and also the path are not really clear.
I hope there's a solution, and that with such a structure it will not be impossible because I'd rather not rewrote each path in the scripts ...
Further informations :
the setup.py script is in lib folder and looks like that:
from cx_Freeze import setup, Executable
setup(
name = "Resets",
version = "1.0",
description = "Jeu de plateforme - Projet ISN 2014",
executables = [Executable("Menu.py")]
)
And i get this error when I launch the Menu.exe :
Traceback (most recent call last):
File "C:\Python32\lib\site-packages\pygame\__init__.py", line 117, in <module>
try: import pygame.display
File "ExtensionLoader_pygame_display.py", line 22, in <module>
File "ExtensionLoader_pygame_display.py", line 14, in __bootstrap__
File "ExtensionLoader_pygame_surface.py", line 22, in <module>
File "ExtensionLoader_pygame_surface.py", line 14, in __bootstrap__
ImportError: No module named _view
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Python32\lib\site-packages\cx_Freeze\initscripts\Console3.py", line 2
7, in <module>
exec(code, m.__dict__)
File "Menu.py", line 8, in <module>
File "C:\Python32\lib\site-packages\pygame\__init__.py", line 118, in <module>
except (ImportError,IOError):display=MissingModule("display", geterror(), 1)
File "C:\Python32\lib\site-packages\pygame\__init__.py", line 61, in __init__
self.warn()
File "C:\Python32\lib\site-packages\pygame\__init__.py", line 85, in warn
warnings.warn(message, RuntimeWarning, level)
File "C:\Python\32-bit\3.2\lib\warnings.py", line 18, in showwarning
File "C:\Python\32-bit\3.2\lib\warnings.py", line 25, in formatwarning
File "C:\Python\32-bit\3.2\lib\linecache.py", line 15, in getline
File "C:\Python\32-bit\3.2\lib\linecache.py", line 41, in getlines
File "C:\Python\32-bit\3.2\lib\linecache.py", line 127, in updatecache
File "C:\Python\32-bit\3.2\lib\codecs.py", line 300, in decode
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x90 in position 2: invalid
start byte
I already try with import pygame._view and import re but it doesn't work too...
Finally I succeeded, it was very simple !
I added import pygame._view in each script. And I copied the data folder into the folder (after being compiled).
Related
I just tried to use py5 in thonny, but everytime i have the py5 mode on and try to run a code i get a bunch of error messeges, i dont really know what they mean so maybe somebody can help me out ?
thanks in advance
This is the error im always getting
Traceback (most recent call last):
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\py5_tools\tools\run_sketch.py", line 52, in <module>
main()
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\py5_tools\tools\run_sketch.py", line 44, in main
imported.run_code(
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\py5_tools\imported.py", line 135, in run_code
_run_code(
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\py5_tools\imported.py", line 259, in _run_code
_run_sketch(sketch_path, classpath, exit_if_error)
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\py5_tools\imported.py", line 196, in _run_sketch
import py5
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\py5\__init__.py", line 84, in <module>
from py5_tools.magics import load_ipython_extension # noqa
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\py5_tools\magics\__init__.py", line 22, in <module>
from .drawing import DrawingMagics, DXFDrawingMagic
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\py5_tools\magics\drawing.py", line 27, in <module>
from IPython.display import display, SVG, Image
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\IPython\__init__.py", line 51, in <module>
from .core.application import Application
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\IPython\core\application.py", line 26, in <module>
from IPython.core import release, crashhandler
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\IPython\core\crashhandler.py", line 27, in <module>
from IPython.core import ultratb
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\IPython\core\ultratb.py", line 101, in <module>
import stack_data
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\stack_data\__init__.py", line 1, in <module>
from .core import Source, FrameInfo, markers_from_ranges, Options, LINE_GAP, Line, Variable, RangeInLine, \
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\stack_data\core.py", line 19, in <module>
from stack_data.utils import (
File "C:\Users\schwe\AppData\Roaming\Thonny\plugins\Python310\site-packages\stack_data\utils.py", line 11, in <module>
from asttokens import ASTText
ImportError: cannot import name 'ASTText' from 'asttokens' (C:\Users\schwe\AppData\Local\Programs\Thonny\lib\site-packages\asttokens\__init__.py)
I received a response from the py5 developer via Github. They also provided an explanation but it goes over my head, something about "The Python library asttokens is used for parsing syntax trees and syntax highlighting. It is not used by py5 but it might be used by Jupyter Notebook and/or JupyterLab.". They also provided a solution here:
enter link description here
I want to use pwntools(which is python module) in my mac. However I get error instead of pwntools. I tried all step in https://github.com/Gallopsled/pwntools/issues. But I get
Traceback (most recent call last):
File "/Users/Knight/PycharmProjects/untitled/gmail.py", line 1, in <module>
import pwn
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pwn/__init__.py", line 2, in <module>
from .toplevel import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pwn/toplevel.py", line 20, in <module>
import pwnlib
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pwnlib/__init__.py", line 40, in <module>
importlib.import_module('.%s' % module, 'pwnlib')
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pwnlib/args.py", line 10, in <module>
from . import term
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pwnlib/term/__init__.py", line 3, in <module>
from . import completer
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pwnlib/term/completer.py", line 4, in <module>
from . import readline
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pwnlib/term/readline.py", line 4, in <module>
from . import text
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pwnlib/term/text.py", line 115, in <module>
sys.modules[__name__] = Module()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pwnlib/term/text.py", line 26, in __init__
self.num_colors = termcap.get('colors', default = 8)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pwnlib/term/termcap.py", line 25, in get
s = curses.tigetstr(cap)
_curses.error: must call (at least) setupterm() first
I can't understand why I can't use it.
Help me please
You must set the following environment variables as indicated here
export TERM=linux
export TERMINFO=/etc/terminfo
Setupterm could not find terminal, in Python program using curses
I'm sure I've done something stupid and the answer is simple, but I can't find it... I want to use pygal on GAE, so I have copied the whole pygal directory to my lib directory. Then, I import it (from another file in lib):
import pygal
Now I get:
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "main.py", line 18, in <module>
from lib import output_lib
File "lib\output_lib.py", line 14, in <module>
import pygal
File "lib\pygal\__init__.py", line 34, in <module>
from pygal.graph.bar import Bar
ImportError: No module named pygal.graph.bar
I can fix this by changing
from pygal.graph.bar import Bar
in pygal/__init__.py to
from graph.bar import Bar
but this leads to the next iteration of the error:
...
File "lib\pygal\__init__.py", line 34, in <module>
from graph.bar import Bar
File "lib\pygal\graph\bar.py", line 27, in <module>
from pygal.graph.graph import Graph
ImportError: No module named pygal.graph.graph
So - what's the problem here?
For want of a better solution, I replaced all occurrences of from pygal.* to from lib.pygal.* in all files' import statements. It works, though I still think there must be another way...
I have created an exe file using py2exe, however it gives me an Attribute error and an import error on execution. I have used urllib2 and BeautifulSoup in my main script, which is abc.py
Here is my setup.py:
from distutils.core import setup
import py2exe
setup(console=['abc.py'])
options={"py2exe": {'includes': ["BeautifulSoup"]}}
I have added the 'includes' parameter after referring to another question on this website. It however doesn't work for me.
The output I get from abc.exe is
C:\Users\Dhruv Mullick\Desktop\dist>abc.exe Traceback (most recent
call last): File
"C:\Python27\lib\site-packages\py2exe\boot_common.py", line 92, in
import linecache File "linecache.pyc", line 9, in File "os.pyc", line 398, in File "UserDict.pyc", line 83,
in File "_abcoll.pyc", line 11, in File
"abc.pyc", line 3, in File "bs4__init__.pyc", line 30, in
File "bs4\builder__init__.pyc", line 1, in File
"collections.pyc", line 6, in AttributeError: 'module' object
has no attribute 'all' Traceback (most recent call last): File
"abc.py", line 3, in File "bs4__init__.pyc", line 26, in
File "os.pyc", line 398, in File "UserDict.pyc",
line 83, in File "_abcoll.pyc", line 11, in File
"abc.pyc", line 3, in ImportError: cannot import name
BeautifulSoup
C:\Users\Dhruv Mullick\Desktop\dist>
Your script 'abc.py' conflicts with the abc module in Python's standardlibrary.
Rename the script to something else (maybe abc_app.py), adapt the setup-script and rebuild.
You should also make sure to remove any 'abc.pyc' or 'abc.pyo' files which you may have. And remove the 'build' directory that py2exe creates...
I'm having trouble removing a resource file in a pyqt document, I'm also using monkeystudio IDE. I madea program with images and all linked to a resource file called "resources.qyc" and now I get the error
Traceback (most recent call last):
File "main.py", line 9, in <module>
from Login import Login
File "J:\Newone\Login.py", line 3, in <module>
import mainwindow
File "J:\Newone\mainwindow.py", line 2, in <module>
import Addcadet
File "J:\Newone\Addcadet.py", line 6, in <module>
( Ui_Addcadet, QDialog ) = uic.loadUiType( 'Addcadet.ui' )
File "C:\Python32\lib\site-packages\PyQt4\uic\__init__.py", line 203, in loadUiType
exec(code_string.getvalue(), ui_globals)
File "<string>", line 179, in <module>
ImportError: No module named resources_rc
You'll first have to compile the resource file using pyrcc4. You'll run something like this from command line:
pyrcc4 ResourceFile.qrc -o ui_ResourceFile.py