What's wrong in python script? - python

What's wrong in python script?
Code:
import os
import shutil
import getpass
os.mkdir("C:\\dtmp")
shutil.copy("C:\\path\\to\\bb-freeze-script.py","C:\\dtmp")
os.chdir("C:\\dtmp")
shutil.copy("C:\\path\\to\\main.py","C:\\dtmp")
os.system("python bb-freeze-script.py main.py")
os.mkdir("C:\\Program Files\\Directories v0.6")
os.chdir("C:\\")
shutil.rmtree("C:\\dtmp")
print getpass.getuser()
Error:
Traceback (most recent call last):
File "bb-freeze-script.py", line 8, in <module>
load_entry_point('bbfreeze==0.97.3', 'console_scripts', 'bb-freeze')()
File "C:\Python27\lib\site-packages\bbfreeze-0.97.3-py2.7-win32.egg\bbfreeze\__init__.py", line 24, in main
f.addScript(x)
File "C:\Python27\lib\site-packages\bbfreeze-0.97.3-py2.7-win32.egg\bbfreeze\freezer.py", line 410, in addScript
s = self.mf.run_script(path)
File "C:\Python27\lib\site-packages\bbfreeze-0.97.3-py2.7-win32.egg\bbfreeze\modulegraph\modulegraph.py", line 241, in run_script
co = compile(file(pathname, READ_MODE).read()+'\n', pathname, 'exec')
File "C:\dtmp\main.py", line 14
^
IndentationError: expected an indented block
Operating system -- Windows XP

Here's a quick walkthrough on how to read tracebacks. It's pretty easy.
Looking through your code, all of it is calling Python builtin modules. It's safe to say they're not causing the error, so the only thing left is the os.system call. Sure enough, you're calling python through said call (why would you not just import the module you want to call?).
The traceback confirms that the error is in the other Python you are calling:
Traceback (most recent call last):
File "bb-freeze-script.py", line 8, in <module>
load_entry_point('bbfreeze==0.97.3', 'console_scripts', 'bb-freeze')()
Next, read through the lines of the transcript to burrow through the call stack and find out exactly where the error occurred.
File "C:\Python27\lib\site-packages\bbfreeze-0.97.3-py2.7-win32.egg\bbfreeze\__init__.py", line 24, in main
f.addScript(x)
File "C:\Python27\lib\site-packages\bbfreeze-0.97.3-py2.7-win32.egg\bbfreeze\freezer.py", line 410, in addScript
s = self.mf.run_script(path)
File "C:\Python27\lib\site-packages\bbfreeze-0.97.3-py2.7-win32.egg\bbfreeze\modulegraph\modulegraph.py", line 241, in run_script
co = compile(file(pathname, READ_MODE).read()+'\n', pathname, 'exec')
until you get to
File "C:\dtmp\main.py", line 14
IndentationError: expected an indented block
There you go, the error is in line 14 of main.py, where you should have had an indent but didn't.

Related

Error in pox controller in sdn using python2 and python3 for detectionEntropy

I am trying to run pox controller using the command
python2 ./pox.py forwarding.​ l3_detectionEntropyemphasized text
Then I got this error.
` Traceback (most recent call last):
File "./pox.py", line 43, in <module>
from pox.boot import boot
File "/home/name/pox/pox/boot.py", line 38, in <module>
import pox.core
File "/home/name/pox/pox/core.py", line 182, in <module>
import pox.lib.recoco as recoco
File "/home/name/pox/pox/lib/recoco/__init__.py", line 1, in <module>
from .recoco import *
File "/home/name/pox/pox/lib/recoco/recoco.py", line 17, in <module>
from queue import PriorityQueue
ImportError: No module named queue`
Also I have tried to run it in python3 by converting it into python3 Then i got this error.
`Traceback (most recent call last):
File "/home/shivani/pox/pox/boot.py", line 74, in do_import2
__import__(name, level=0)
File "/home/shivani/pox/pox/forwarding/l3_detectionEntropy.py", line 129
print "dpid port and its packet count: ", str(event.connection.dpid),
str(diction[event.connection.dpid]), str(diction[event.connection.dpid][event.port])
^
SyntaxError: invalid syntax
Could not import module: forwarding.l3_detectionEntropy`
How to solve these error??
Adding paranthesis around the print statement should fix the issue.
Python 3 would raise a SyntaxError if we called the print function the Python 2-way without the parentheses.

How can I run many python scripts at once?

I'm working on some python scripts using PyCharm. Running scripts from PyCharm works fine, but I tried bundling them up with a batch file and cmd just goes nuts:
C:\Users\White Python\Desktop\Fran\theconfluence\graphs\leaderboard>python htmlcreator.py
Traceback (most recent call last):
File "htmlcreator.py", line 4, in <module>
w = open(str(Path(__file__).parents[2]) + "/week.txt", "r")
File "C:\Users\White Python\AppData\Local\Programs\Python\Python38-32\lib\pathlib.py", line 617, in __getitem__
raise IndexError(idx)
IndexError: 2
C:\Users\White Python\Desktop\Fran\theconfluence\graphs\leaderboard>cd ..\retention
C:\Users\White Python\Desktop\Fran\theconfluence\graphs\retention>python creategraph.py
['C:\\Users\\White Python\\Desktop\\Fran\\theconfluence\\graphs\\retention', 'C:\\Users\\White Python\\AppData\\Local\\Programs\\Python
\\Python38-32\\python38.zip', 'C:\\Users\\White Python\\AppData\\Local\\Programs\\Python\\Python38-32\\DLLs', 'C:\\Users\\White Python\
\AppData\\Local\\Programs\\Python\\Python38-32\\lib', 'C:\\Users\\White Python\\AppData\\Local\\Programs\\Python\\Python38-32', 'C:\\Us
ers\\White Python\\AppData\\Local\\Programs\\Python\\Python38-32\\lib\\site-packages']
Traceback (most recent call last):
File "creategraph.py", line 9, in <module>
w = open(str(Path(__file__).parents[2]) + "/week.txt", "r")
File "C:\Users\White Python\AppData\Local\Programs\Python\Python38-32\lib\pathlib.py", line 617, in __getitem__
raise IndexError(idx)
IndexError: 2
Other scripts which did not require importing modules worked fine. Help!
Is your html creator a script? Or more like module? If it's like a module the try:
python -m htmlcreator

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

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?)

Can not import theano after installation windows 10

I've still not been able to resolve this problem, after working on it for a week.
I'm thinking of giving up and just running theano on a virutal machine; there just doesn't seem to be any support out there for Windows 10!
Or am I wrong; is there an easy fix to this?
>>> import theano
Traceback (most recent call last):
File "C:\Users\cturn\Anaconda3\lib\site-packages\theano\theano\gof\lazylinker_c.py", line 75, in <module>
raise ImportError()
ImportError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\cturn\Anaconda3\lib\site-packages\theano\theano\gof\lazylinker_c.py", line 92, in <module>
raise ImportError()
ImportError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\cturn\Anaconda3\lib\site-packages\theano\theano\gof\cmodule.py", line 1784, in _try_compile_tmp
os.remove(exe_path + ".exe")
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\cturn\\AppData\\Local\\Temp\\try_march_3v6ffkv9.exe'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\cturn\Anaconda3\lib\site-packages\theano\theano\__init__.py", line 66, in <module>
from theano.compile import (
File "C:\Users\cturn\Anaconda3\lib\site-packages\theano\theano\compile\__init__.py", line 10, in <module>
from theano.compile.function_module import *
File "C:\Users\cturn\Anaconda3\lib\site-packages\theano\theano\compile\function_module.py", line 21, in <module>
import theano.compile.mode
File "C:\Users\cturn\Anaconda3\lib\site-packages\theano\theano\compile\mode.py", line 10, in <module>
import theano.gof.vm
File "C:\Users\cturn\Anaconda3\lib\site-packages\theano\theano\gof\vm.py", line 659, in <module>
from . import lazylinker_c
File "C:\Users\cturn\Anaconda3\lib\site-packages\theano\theano\gof\lazylinker_c.py", line 125, in <module>
args = cmodule.GCC_compiler.compile_args()
File "C:\Users\cturn\Anaconda3\lib\site-packages\theano\theano\gof\cmodule.py", line 2088, in compile_args
default_compilation_result, default_execution_result = try_march_flag(GCC_compiler.march_flags)
File "C:\Users\cturn\Anaconda3\lib\site-packages\theano\theano\gof\cmodule.py", line 1856, in try_march_flag
flags=cflags, try_run=True)
File "C:\Users\cturn\Anaconda3\lib\site-packages\theano\theano\gof\cmodule.py", line 2188, in try_compile_tmp
comp_args)
File "C:\Users\cturn\Anaconda3\lib\site-packages\theano\theano\gof\cmodule.py", line 1789, in _try_compile_tmp
err += "\n" + str(e)
TypeError: can't concat bytes to str
Um, can't concat bytes to str? What does this mean?
The error you are experiencing appears to result from another sub-process utilizing the same resources as the script you are attempting to write. Although it sounds trivial, I would recommend making sure that you have admin privileges, or at least privileges to the desired resources, and/or restart your computer to kill the sub-process using that module. You could also look in the task manager and kill any/all other processes using python, but that might take longer.
(This may be the program using the "resource" try_march_3v6ffkv9.exe)

How should I solve Attribute and Import errors generated on using py2exe?

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...

Categories

Resources