I'm trying to run my python code using sublimeREPL's "Python - RUN current file" command
It works fine if my program has no problems, but when it does, it doesn't show the complete Traceback (I don't get to see the "Repl Closed" message), and the output its not even consistent. Below two runs of the exactly same file (not posting images because stackoverflow doesn't allows me to because I'm new):
First Run:
------- Ford Fulkerson -------
Traceback (most recent call last):
File "Ford-Fulkerson.py", line 282, in <module>
D = FordFulkersonGeneral(G, ['A'], ['E'], None, restricciones)
File "Ford-Fulkerson.py", line 71, in FordFulk|
Second Run:
------- Ford Fulkerson -------
Traceback (most recent call last):
File "Ford-Fulkerson.py", line 282, in <module>
D = FordFulkersonGeneral(G, ['A'], ['E'
I was using the Anaconda's (64 bit) python distribution. Then I changed to a regular python (32 bit) install (made sure the window's path was all right) and even there its not working.
If I run my code from window's terminal I get the full Traceback (the actual error is not important, I know how to fix it):
------- Ford Fulkerson -------
Traceback (most recent call last):
File "Ford-Fulkerson.py", line 282, in <module>
D = FordFulkersonGeneral(G, ['A'], ['E'], None, restricciones)
File "Ford-Fulkerson.py", line 71, in FordFulkersonGeneral
G.deleteNode(v)
File "C:\Users\myusername\Documents\Learning\Anßlisis de Re
des\Ford-Fulkerson\mvr_graph.py", line 196, in deleteNode
self.nodes[node].delete(n)
AttributeError: 'dict' object has no attribute 'delete'
Edit:
I've found the answer by posting this question. The problem was in the path of the file - it contains an accent in the word "Análisis". I changed that and know its working.
It used to work when I had my OS language set to spanish. I set my new installation to english and now it was giving me trouble. I really didn't expected that, shame on you Windows x(.
I don't really know the protocol, I will just leave this question here in case anyone is going through this obscure thing.
I've found the answer by posting this question. The problem was in the path of the file - it contains an accent in the word "Análisis". I changed that and know its working.
It used to work when I had my OS language set to spanish. I set my new installation to english and now it was giving me troubles. I really didn't expected that, shame on you Windows x(.
Related
Anyone familiar with this error?
Traceback (most recent call last):
File "C:/Users/Geebug/Documents/ParameterEstimationGekko_v6.py", line 104, in <module>
m.solve()
File "C:\Users\Geebug\AppData\Local\Programs\Python\Python39\lib\site-packages\gekko\gekko.py", line 2227, in solve
self.load_JSON()
File "C:\Users\Geebug\AppData\Local\Programs\Python\Python39\lib\site-packages\gekko\gk_post_solve.py", line 70, in load_JSON
vp.__dict__[o] = data[vp.name][o]
KeyError: 'v5'
I am trying to solve a (parameter estimation) optimization problem in a loop using Gekko, such that the values of the parameter changes with every iteration and solves. The problem solve only the first two iterations and produces the above error message after the second iteration.
The KeyError is likely due a Gekko variable that is redefined as another Gekko variable so it no longer exists as an output. The error happens when the solution is returned to Python and loaded back into x.value after a solution is found.
I use a lot of special characters from Hun language, and there were no problems previously. Now they all give errors when running the whole script (F9). It still runs perfect when running locally (select + F5).
Fúú='bar'
Traceback:
C:\Users\my name\.ipython\cython\_cython_magic_21a3824690cdb52a9fe6a3fa1c63ee73.pyx:1:1: Unrecognized character
Traceback (most recent call last):
File "<ipython-input-6-dcfab52d0ff4>", line 1, in <module>
runfile('E:/Anyagok/Programozas/Python/projekts/elo/mindennap/untitled0.pyx', wdir='E:/Anyagok/Programozas/Python/projekts/elo/mindennap')
File "E:\Download\PROGIK\ANACONDA\lib\site-packages\spyder\utils\site\sitecustomize.py", line 703, in runfile
ipython_shell.run_cell_magic('cython', '', f.read())
File "E:\Download\PROGIK\ANACONDA\lib\site-packages\IPython\core\interactiveshell.py", line 2131, in run_cell_magic
result = fn(magic_arg_s, cell)
File "<decorator-gen-130>", line 2, in cython
File "E:\Download\PROGIK\ANACONDA\lib\site-packages\IPython\core\magic.py", line 187, in <lambda>
call = lambda f, *a, **k: f(*a, **k)
File "E:\Download\PROGIK\ANACONDA\lib\site-packages\Cython\Build\IpythonMagic.py", line 321, in cython
assert len(extensions) == 1
TypeError: object of type 'NoneType' has no len()
If I change to e.g.
Fuu='bar'
it works great. Why the sudden change of heart?
EDIT:
Have been messing around with FFMPEG and LIBAV yesterday, because wanted to download and convert Youtube videos to mp3. But I'm pretty sure I ran scripts with these characters succesfully after it.
This code form RubyMonk works in RubyMonk:
class Calculator
def add(a, b)
a + b
end
def subtract(a, b)
a - b
end
end
I copied it to Sublime Text 2, set the build system to Ruby, then I saved it. When I type in the console something like add(1, 2), I get the following exception:
Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name 'add' is not defined
I couldn't find a solution to this. I tried reinstalling Sublime Text 2, tried the beta of ST3, tried other code which I know to be good (same error), etc., and nothing is working. Any ideas?
EDIT: On the suggestion of another user, I tried:
Calculator.new.add(1, 2)
which returned:
Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name 'Calculator' is not defined
Sublime Text 2 console is python console, not ruby.
Additionally your ruby code is incorrect.
I have the sensation that you're calling the method add(1,2) for no Object at all. What I mean is, in this case, that you're not telling the Calculator to add, but just to the thin air... which does not know how to add!
Try doing th following:
Calculator.new.add(1,2)
And you'll be asking an instance of the Calculator to add.
Tell me if you have any doubts or if I'm completely mistaken!
EDIT: As stated by texasbruce, ST2 console is Python. Therefore, the solution is the following:
Add puts Calculator.new.add(1,2) in the code and hit Ctrl+B to launch Ruby.
I am writing this Python program which extracts some information from a webpage and I am required to run it using the windows command line. But I could not even print the original html page as a string. I am using Python 2.7
Here is my Python script:
#sys.py
import sys
import urllib
url = sys.argv[1]
f = urllib.urlopen(url)
print f.read()
When I try to run it from windows command line with: C...>sys.py "www.marinetraffic.com/ais/shipdetails.aspx?mmsi=311389000"
Errors appear as follows:
Traceback(most recent call last):
File "C:\...\sys.py", line 14 in <module>
f = urllib.urlopen(url)
File "C:\Python27\lib\urllib.py", line 87, in urlopen
return opener.open(url)
File "C:\Python27\lib\urllib.py", line 208, in open
return getattr(self, name)(url)
File "C:\Python27\lib\urllib.py", line 463, in open_file
return self.open_local_file(url)
File "C:\Python27\lib\urllib.py", line 87, in open_loca_file
raise IOError(e.errno, e.strerror, e.filename)
IOError: [Errno 2] The system cannot find the path specified: 'www.marinetraffic.com\\ais\\shipdetails.aspx?mmsi=311389000'
There should not be any problem with the Python set up under the windows environment because I can still print out the sys.argv list as the arguments are passed in the command line.
Is it the problem with the 'urllib' library?
Is there any another way to run this using windows command line?
I think the problem is the way you specify your url, it needs to have the http:// part at the start.
It works for me when I type
python sys.py http://www.google.com/
but fails with
python sys.py www.google.com
(Note that I am using linux with python 2.7 but I think it may be the same problem for you)
My test code is:
#!/usr/bin/env python
import win32com.client
def GetFolderSizeQuick(target_folder):
fso = win32com.client.Dispatch("Scripting.FileSystemObject")
fobj = fso.GetFolder(target_folder)
return fobj.size
print(GetFolderSizeQuick("d:/pytools"))
print(GetFolderSizeQuick("d:/cygwin"))
The result is:
D:\>python a.py
160659697
Traceback (most recent call last):
File "a.py", line 10, in <module>
print(GetFolderSizeQuick("d:/cygwin"))
File "a.py", line 7, in GetFolderSizeQuick
return fobj.size
File "D:\Applications\Python33\lib\site-packages\win32com\client\dynamic.py",
line 511, in __getattr__
ret = self._oleobj_.Invoke(retEntry.dispid,0,invoke_type,1)
pywintypes.com_error: (-2147352567, '发生意外。', (0, None, None, None, 0, -2146828218), None)
The first call GetFolderSizeQuick on d:/pytools folder works. it's about 153MB. But the second call failed. The folder d:/cygwin is about 12.6GB.
I am working on windows 7 with python3.3.0 32bit version. So I think the problem happened on the 32bit or 64bit to store the result. 32bit int can not store 12.6GB size.
What is the real problem here, and how to fix it?
That's neither a directory size nor a 32/64-Bit problem.
It's even not a python2 or python3 problem.
Your Error translates to "No Access allowed!"
The simpliest way for testing would be to create a directory where only the owner is allowed to read and all others have NO rights at all. Then take this directory as input - you'll get the same error, even if the directory is empty. A good example would be the local "c:\system Volume Information".
Digging a little deeper:
The errorcodes given by python are signed, whereas for a reasonable lookup Microsoft describes and expects them as unsigned. Kudos to EB in this thread and Tim Peters in this thread, using the examples, you'll get reasonable error-Codes.
import win32com.client
import pywintypes
def get_folder_size(target_folder):
fso = win32com.client.Dispatch("Scripting.FileSystemObject")
fobj = fso.GetFolder(target_folder)
return fobj.size
if __name__ == '__main__':
try:
get_folder_size('c:/system volume information')
except pywintypes.com_error, e:
print e # debug, have to see which indices
print hex(e[0]+2**32), hex(e[2][5]+2**32)
Now search for both of the hex digits, the 2nd one should lead to a lot of "you are not allowed to..." queries and answers.