Run a .py file ... Save Report Mouchasounet - Last answer on 29 avr. 2015 20 answers Hello, I downloaded a script from the internet, so I opened it with Python since it is in .py format, and I would like to run the program. What should I do? Configuration: Windows XP Firefox 2.0.0.6 Show more Related links: run a sh script look for a dictionary list in .TXT [python] Search for a string in a file run a .py file on Linux launch a python program from a shell script Pix Certification - Python and SQL 20 answers Sorted by votes Votes Date Descending date Answer 1 / 20 - Best answer The best answer is the one that has been validated by our teams. ... Report sebsauvage Moderator Open an MS-Dos window, type: python monprogramme.py If it doesn't work, you need to add Python to the PATH (environment variable). Answer 2 / 20 ... Report sebsauvage Moderator to run a Python program, 2 solutions: - In a command window, type: python programme.py - Rename the .py to .pyw and double-click on it (but in this case, you won't see the console) Answer 3 / 20 ... Report Mouchasounet Author Here’s what it looks like: http://img72.imageshack.us/img72/8287/pythonmn9.jpg Answer 4 / 20 ... Report Mouchasounet Author Maybe an error in the code.. #!/usr/bin/env python # devloop 2006 import sys, socket, urllib2 if len(sys.argv) < 2: print "Usage: python statsliar.py url <referer_url>" sys.exit(1) url = sys.argv[1] if not url.startswith("http://"): print "Not a valid url" sys.exit(1) if len(sys.argv) == 3: if sys.argv[2].startswith("http://"): referer = sys.argv[2] else: print "Not a valid referer" sys.exit(1) else: referer = "" head = {'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)', 'Referer': 'http://proxy-list.org/downloadproxylist.php?sp=-1&pp=any&pt=any&pc=any&ps=any'} socket.setdefaulttimeout(10) try: req = urllib2.Request("http://proxy-list.org/downloadproxylist.php?sp=-1&pp=any&pt=any&pc=any&ps=any", headers=head) proxylist = urllib2.urlopen(req).readlines() except IOError: print "Error reading proxy list" sys.exit(1) print "Fetching url " + url head = {'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'} if referer != "": head["Referer"] = referer print "Using referer " + referer for prox in proxylist: prox = prox.strip() try: req = urllib2.Request(url, headers=head) req.set_proxy(prox, 'http') urllib2.urlopen(req) except IOError: continue print prox</referer_url> ... Report nom Yes Answer 5 / 20 ... Report sebsauvage Moderator Here I get started and he tells me "Usage statsliar.py python url <referer_url> Here he indicates how to use the software. It means that you need to pass a URL in the command line. Example: python statsliar.py https://www.toto.com/ If I understand correctly, this script is used to manipulate the stats of a site using proxies. Hmmpf... :-/ What I think about it, huh... Answer 6 / 20 ... Report Mouchasounet Author I have Python 2.2.3 Answer 7 / 20 ... Report sebsauvage Moderator That must be why. Uninstall your version of Python and install 2.5.1: https://www.python.org/ftp/python/2.5.1/python-2.5.1.msi Answer 8 / 20 ... Report sebsauvage Moderator It’s that the program displays things in the console. So it needs to be run in a console (and not as .pyw). Answer 9 / 20 ... Report Mouchasounet Author "Python : Impossible d'ouvrir le fichier "statliars.py"" Answer 10 / 20 ... Report sebsauvage Moderator Did you navigate to the directory of your .py program before typing the command? Answer 11 / 20 ... Report Mouchasounet Author No, how should I do it? Answer 12 / 20 ... Report sebsauvage Moderator Use the CD command to change the directory and place yourself in the directory where your script is located. Answer 13 / 20 ... Report Mouchasounet Author Here I start and he tells me "Usage statsliar.py python url <referer_url>"</referer_url> Answer 14 / 20 ... Report Mouchasounet Author Yes, but why do they give me an error after? Answer 15 / 20 ... Report sebsauvage Moderator No idea. At my place, the line socket.setdefaulttimeout(10) does not cause any error. What version of Python do you have? Type: python --version Answer 16 / 20 ... Report Mouchasounet Author Here's how to add Python to the PATH. Answer 17 / 20 ... Report sebsauvage Moderator Right-click on My Computer > Properties Advanced tab "Environment Variables" button In the lower part (System variables) select PATH and click on the "Edit" button. In "Variable value", go to the end of the line and add: ;c:\python25 (Don't forget the semicolon just before c:\python25) Confirm everything by clicking OK. You may need to restart for the changes to take effect. Answer 18 / 20 ... Report kumakuma215 Hello, CMD does not recognize the Python command, what should I do??? ... Report anonymous you need to add it to the path Answer 19 / 20 ... Report Mouchasounet Author Yes, but it doesn't execute (nothing launches in .pyw). Answer 20 / 20 ... Report Mouchasounet Author And how? Show full discussion
Answer 1 / 20 - Best answer The best answer is the one that has been validated by our teams. ... Report sebsauvage Moderator Open an MS-Dos window, type: python monprogramme.py If it doesn't work, you need to add Python to the PATH (environment variable).
Answer 2 / 20 ... Report sebsauvage Moderator to run a Python program, 2 solutions: - In a command window, type: python programme.py - Rename the .py to .pyw and double-click on it (but in this case, you won't see the console)
Answer 3 / 20 ... Report Mouchasounet Author Here’s what it looks like: http://img72.imageshack.us/img72/8287/pythonmn9.jpg
Answer 4 / 20 ... Report Mouchasounet Author Maybe an error in the code.. #!/usr/bin/env python # devloop 2006 import sys, socket, urllib2 if len(sys.argv) < 2: print "Usage: python statsliar.py url <referer_url>" sys.exit(1) url = sys.argv[1] if not url.startswith("http://"): print "Not a valid url" sys.exit(1) if len(sys.argv) == 3: if sys.argv[2].startswith("http://"): referer = sys.argv[2] else: print "Not a valid referer" sys.exit(1) else: referer = "" head = {'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)', 'Referer': 'http://proxy-list.org/downloadproxylist.php?sp=-1&pp=any&pt=any&pc=any&ps=any'} socket.setdefaulttimeout(10) try: req = urllib2.Request("http://proxy-list.org/downloadproxylist.php?sp=-1&pp=any&pt=any&pc=any&ps=any", headers=head) proxylist = urllib2.urlopen(req).readlines() except IOError: print "Error reading proxy list" sys.exit(1) print "Fetching url " + url head = {'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'} if referer != "": head["Referer"] = referer print "Using referer " + referer for prox in proxylist: prox = prox.strip() try: req = urllib2.Request(url, headers=head) req.set_proxy(prox, 'http') urllib2.urlopen(req) except IOError: continue print prox</referer_url> ... Report nom Yes
Answer 5 / 20 ... Report sebsauvage Moderator Here I get started and he tells me "Usage statsliar.py python url <referer_url> Here he indicates how to use the software. It means that you need to pass a URL in the command line. Example: python statsliar.py https://www.toto.com/ If I understand correctly, this script is used to manipulate the stats of a site using proxies. Hmmpf... :-/ What I think about it, huh...
Answer 7 / 20 ... Report sebsauvage Moderator That must be why. Uninstall your version of Python and install 2.5.1: https://www.python.org/ftp/python/2.5.1/python-2.5.1.msi
Answer 8 / 20 ... Report sebsauvage Moderator It’s that the program displays things in the console. So it needs to be run in a console (and not as .pyw).
Answer 9 / 20 ... Report Mouchasounet Author "Python : Impossible d'ouvrir le fichier "statliars.py""
Answer 10 / 20 ... Report sebsauvage Moderator Did you navigate to the directory of your .py program before typing the command?
Answer 12 / 20 ... Report sebsauvage Moderator Use the CD command to change the directory and place yourself in the directory where your script is located.
Answer 13 / 20 ... Report Mouchasounet Author Here I start and he tells me "Usage statsliar.py python url <referer_url>"</referer_url>
Answer 15 / 20 ... Report sebsauvage Moderator No idea. At my place, the line socket.setdefaulttimeout(10) does not cause any error. What version of Python do you have? Type: python --version
Answer 17 / 20 ... Report sebsauvage Moderator Right-click on My Computer > Properties Advanced tab "Environment Variables" button In the lower part (System variables) select PATH and click on the "Edit" button. In "Variable value", go to the end of the line and add: ;c:\python25 (Don't forget the semicolon just before c:\python25) Confirm everything by clicking OK. You may need to restart for the changes to take effect.
Answer 18 / 20 ... Report kumakuma215 Hello, CMD does not recognize the Python command, what should I do??? ... Report anonymous you need to add it to the path
Answer 19 / 20 ... Report Mouchasounet Author Yes, but it doesn't execute (nothing launches in .pyw).