ImportError: No module named __main__ (Python 2.7 & Pickle) - python

So on my game I'm making, I'm trying to load the data files needed for the game, and when I load the file with pickle (The file has been loaded, I've double-checked that.) I get this error:
Traceback (most recent call last):
File "/Users/user/Downloads/Deeper-master/Deeper.py", line 257, in <module>
tutorialData = pickle.load(tutorialFile)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 1384, in load
return Unpickler(file).load()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 864, in load
dispatch[key](self)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 1075, in load_inst
klass = self.find_class(module, name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 1130, in find_class
__import__(module)
ImportError: No module named __main__
I saw a question like this on Stack Overflow, but it's a little different than my situation, so sorry if this is a duplicate, I'm just trying to figure it out.
You can find my code here. The main script is Deeper.py, just to save time.

If you notice in your repo, you have a Deeper.pyc and Deeper.py. If I run Deeper.py, it raises the same exception as yours. If I run Deeper.pyc, it raises another exception:
Traceback (most recent call last):
File "Deeper.py", line 7, in <module>
ToolbarTile = pygame.image.load("ToolbarTile.png")
pygame.error: Couldn't open Toolbar Tile.png
So, the code (bytecode, some previous version) references ToolbarTile.png, but the exception is about Toolbar Tile.png (with a space). So I changed the file name to account for that.
Now it raises:
Traceback (most recent call last):
File "Deeper.py", line 766, in <module>
else:
File "Deeper.py", line 394, in __init__
def displayCraft(self):
pygame.error: Couldn't open options.png
There's an Options.png in your files, but it looks for options.png (lower case) (even your new code in Deeper.py looks for that). So I changed that.
Now it works, albeit with Deeper.pyc so that must be why you thought:
(The file has been loaded, I've double-checked that.)
Maybe delete the Deeper.pyc and do a git-bisect to see when the bug was introduced (ps: check your toolbar.dat, does it seem okay to you? Also check the way you're using pickle.load. Maybe you should use rb instead of r?)

Related

Getting OSError when running script

I am trying to set up the ChirpSDK, but every time I configure and run the code, I get this error:
Traceback (most recent call last):
File "test.py", line 3, in <module>
chirp = ChirpSDK()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chirpsdk/chirpsdk.py", line 395, in __init__
self.read_chirprc(block)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chirpsdk/chirpsdk.py", line 501, in read_chirprc
raise IOError('Could not find a ~/.chirprc file')
OSError: Could not find a ~/.chirprc file
Exception ignored in: <function ChirpSDK.__del__ at 0x10fa31af0>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chirpsdk/chirpsdk.py", line 422, in __del__
self.close()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chirpsdk/chirpsdk.py", line 470, in close
if self._sdk:
AttributeError: 'ChirpSDK' object has no attribute '_sdk'
I realize that the error is saying that my .chirprc file is not being recognized, but I have no idea how to remedy this. I created a .chirprc file in my /Users/username/ path, and named it c.chirprc (as the Chirp getting started article suggests), but I am still getting this error. Is there another part that I am missing? Am I reading the instructions wrong?
Thanks
The Chirp configuration file should be placed at /Users/<username>/.chirprc on macOS.
If you run ls -l ~/.chirprc in the terminal, do you get any results? If it displays no such file or directory then you have not created the file correctly.

Why did I get the error 'cannot load external tileset'

I just want to know how to fix the error that I mention in the title.
I really don't know what to try, there are only 3 lines of code and they are exactly how it's shown in the doc of pytmx...
import pygame
import pytmx
tmxdata = pytmx.TiledMap("map test pygame.tmx")
I just want to "load" the map that I create without this HUGE error:
Cannot load external tileset: C:\Users\WILHEM\Desktop\brdl Python 3\projet\labyrinthe\test pygame tileset.tsx
Traceback (most recent call last):
File "C:\Users\WILHEM\Desktop\brdl Python 3\projet\labyrinthe\testTMX.py", line 4, in <module>
tmxdata = pytmx.TiledMap("C:/Users/WILHEM/Desktop/brdl Python 3/projet/labyrinthe/carte test pygame.tmx")
File "C:\Users\WILHEM\Desktop\brdl Python 3\Python37-32\lib\site-packages\pytmx\pytmx.py", line 360, in __init__
self.parse_xml(ElementTree.parse(self.filename).getroot())
File "C:\Users\WILHEM\Desktop\brdl Python 3\Python37-32\lib\site-packages\pytmx\pytmx.py", line 400, in parse_xml
self.add_tileset(TiledTileset(self, subnode))
File "C:\Users\WILHEM\Desktop\brdl Python 3\Python37-32\lib\site-packages\pytmx\pytmx.py", line 845, in __init__
self.parse_xml(node)
File "C:\Users\WILHEM\Desktop\brdl Python 3\Python37-32\lib\site-packages\pytmx\pytmx.py", line 874, in parse_xml
raise Exception
Exception
If you can help me... Thank you very much from the bottom of my heart!
from pytmx.util_pygame import load_pygame
load_pygame(filename,pixilalpha=True)

Error exporting inference graph (ValueError)

So I'm following sentdex's object detection tutorial and I have gotten to the step where you are supposed to export the inference graph. I'm using the "export_inference_graph.py" script from Tensorflow's object_detection folder.
The problem is that I'm getting this ValueError:
Traceback (most recent call last):
File "C:\Users\Zelcore-Dator\AppData\Local\Programs\Python\Python35\lib\site-packages\google\proto
buf\internal\python_message.py", line 545, in _GetFieldByName
return message_descriptor.fields_by_name[field_name]
KeyError: 'layout_optimizer'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "export_inference_graph.py", line 119, in <module>
tf.app.run()
File "C:\Users\Zelcore-Dator\AppData\Local\Programs\Python\Python35\lib\site-packages\tensorflow\p
ython\platform\app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "export_inference_graph.py", line 115, in main
FLAGS.output_directory, input_shape)
File "C:\Users\Zelcore-Dator\AppData\Local\Programs\Python\Python35\lib\site-packages\object_detec
tion-0.1-py3.5.egg\object_detection\exporter.py", line 427, in export_inference_graph
input_shape, optimize_graph, output_collection_name)
File "C:\Users\Zelcore-Dator\AppData\Local\Programs\Python\Python35\lib\site-packages\object_detec
tion-0.1-py3.5.egg\object_detection\exporter.py", line 391, in _export_inference_graph
initializer_nodes='')
File "C:\Users\Zelcore-Dator\AppData\Local\Programs\Python\Python35\lib\site-packages\object_detec
tion-0.1-py3.5.egg\object_detection\exporter.py", line 72, in freeze_graph_with_def_protos
layout_optimizer=rewriter_config_pb2.RewriterConfig.ON)
File "C:\Users\Zelcore-Dator\AppData\Local\Programs\Python\Python35\lib\site-packages\google\proto
buf\internal\python_message.py", line 484, in init
field = _GetFieldByName(message_descriptor, field_name)
File "C:\Users\Zelcore-Dator\AppData\Local\Programs\Python\Python35\lib\site-packages\google\proto
buf\internal\python_message.py", line 548, in _GetFieldByName
(message_descriptor.name, field_name))
ValueError: Protocol message RewriterConfig has no "layout_optimizer" field.
I'm guessing that it has something to do with protobuf, but I've reinstalled it several times already with no success.
All help appreciated
Happened to me too. Didn't happen few weeks ago.
Until the bug is fixed, you could use an earlier version that still works.
replace line 72 in 'object_detection/exporter.py':
layout_optimizer=rewriter_config_pb2.RewriterConfig.ON)
with the old and working line:
optimize_tensor_layout=True)
I used:
rewrite_options = rewriter_config_pb2.RewriterConfig(optimize_tensor_layout=True)
but kept running into the same issue UNTIL I went and reran
python setup.py install
from my "research" folder. Then I was able to get everything to work.
Remove optimize_tensor_layout=rewriter_config_pb2.RewriterConfig.ON
change the line 71 in exporter.py
rewrite_options = rewriter_config_pb2.RewriterConfig(optimize_tensor_layout=rewriter_config_pb2.RewriterConfig.ON)
to:
rewrite_options = rewriter_config_pb2.RewriterConfig()

pkg_resources.resource_stream fails on python3

I am trying to load a resource which is present in my project using pkg_resources but it just throws me an exception saying that it quote "Can't perform this operation for loaders without 'get_data()'". I am not sure if I am doing something wrong here, or if pkg_resources is somehow broken on python 3.3. I am using python 3.3.3 to be exact. Here is the code I am trying to execute
>>> import pkg_resources
>>> data = pkg_resources.resource_stream('configgenerator', 'schema_rules.yml')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/users/frank/workspace/configgenerator/env/lib/python3.3/site-packages/distribute-0.6.31-py3.3.egg/pkg_resources.py", line 931, in resource_stream
self, resource_name
File "/home/users/frank/workspace/configgenerator/env/lib/python3.3/site-packages/distribute-0.6.31-py3.3.egg/pkg_resources.py", line 1207, in get_resource_stream
return StringIO(self.get_resource_string(manager, resource_name))
File "/home/users/frank/workspace/configgenerator/env/lib/python3.3/site-packages/distribute-0.6.31-py3.3.egg/pkg_resources.py", line 1210, in get_resource_string
return self._get(self._fn(self.module_path, resource_name))
File "/home/users/frank/workspace/configgenerator/env/lib/python3.3/site-packages/distribute-0.6.31-py3.3.egg/pkg_resources.py", line 1289, in _get
"Can't perform this operation for loaders without 'get_data()'"
NotImplementedError: Can't perform this operation for loaders without 'get_data()'
>>>
Does anyone has an idea on how to fix this?
This can happen for a number of reasons, but the the most common is that the package is not an importable module because there is no __init__.py.

working around an error in a python module

So I have found an error in a module I am using (which one is unimportant, but if you must know it's geopy.distance)
So I know what I have to do to fix the code, but when I open the .py file and edit it, it acts as if it was not edited!
Here is the error traceback before edited:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/geopy-0.95.1-py2.7.egg/geopy/distance.py", line 37, in __init__
kilometers += self.measure(a, b)
File "/Library/Python/2.7/site-packages/geopy-0.95.1-py2.7.egg/geopy/distance.py", line 72, in measure
raise NotImplementedError
NotImplementedError
Here is the error traceback after I edit the file:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/geopy-0.95.1-py2.7.egg/geopy/distance.py", line 37, in __init__
kilometers += self.measure(a, b)
File "/Library/Python/2.7/site-packages/geopy-0.95.1-py2.7.egg/geopy/distance.py", line 72, in measure
a, b = Point(a), Point(b)
NotImplementedError
as you can see, I changed it so it would not raise NotImplementedError, but it is still raising it! How is this possible?
Looks like you've edited a .py file, but the user process doesn't have permission to overwrite the .pyc file. The NotImplementedError is still on line 72 according to the .pyc file, but it's displaying the current line 72 from the .py file
Aside: Looks like Distance is an abstract class. You're not supposed to instantiate directly, but one of the subclasses of it. Eg GreatCircleDistance or VincentyDistance
Also notice the last two lines in the file
# Set the default distance formula to the most generally accurate.
distance = VincentyDistance

Categories

Resources