Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Errors trying to run code
#1
I'm very new to python and received some help to create the code, but it isn't super complicated. I am receiving the following errors when trying to run the code.

Error:
File "C:\Users\Me\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "C:\Users\Me\AppData\Local\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\Users\Me\Documents\GameProgramFolder\py_game\__main__.py", line 85, in <module> main() File "C:\Users\Me\Documents\GameProgramFolder\py_game\__main__.py", line 64, in main module = __import__(os.path.splitext(filename)[0]) File "C:\Users\Me\Documents\GameProgramFolder\py_game\py34.py", line 35, in exec_module exec(code, module.__dict__) File "C:\Users\Me\Documents\GameProgramFolder\Scripts\fight.py", line 3, in <module> import mylibrary File "C:\Users\Me\Documents\GameProgramFolder\py_game\py34.py", line 35, in exec_module exec(code, module.__dict__) File "C:\Users\Me\Documents\GameProgramFolder\py_game\mylibrary.py", line 5, in <module> import requests ModuleNotFoundError: No module named 'requests'
I tried searching for a solution. I added the path environment, uninstalled python and reinstalled, and tried this solution: https://bugs.python.org/msg353736. I don't know enough about what these errors mean to search for a better solution.
Reply
#2
It's hard to figure out what you are trying to do.
try taking this one step at a time.
  • explain what the code is supposed to do
  • what the first step is that you are trying to do
  • The results of that step only.
  • code for the step.
Reply
#3
Ok thank you for the response. I think the issue is something with my pc setup. My friend said they got the code to run for himself.

I'm playing a game that can be run with a client that supports python and has it's own library of functions native to the game. That's the py_game stuff. I have a library of functions that uses py_game and some things that I want to do in-game. The script I'm trying to run is supposed to attack the closest enemy.

I guess the first step is I'm trying to import the py_game library and mylibrary. Then search for all items within a range, filter to enemies, put them in a list, then determine which is closest to attack.

import py_game
import mylibrary

py_game.SetFindDistance(10)
while True:
   searchList = mylibrary.findItems(-1,-1)
   attackables = []
   for it in searchList:
      if py_game.IsNPC(it):
         if it != py_game.Self() and py_game.GetNotoriety(it) > 2:
            attackables.append(it)

   closest = min(attackables,default=None,key=py_game.GetDistance)
   if closest:
      py_game.UseSecondaryAbility()
      py_game.Attack(closest)
      py_game.Wait(500)
   py_game.Wait(20)
The mylibrary starts with these imports if it's relevant:
import py_game
import threading
import enum
import time
import requests
import datetime

I think I've figured it out. With all the errors, I was in information overload, but needed to focus on the final line:

Error:
ModuleNotFoundError: No module named 'requests'
I added that in command line with python -m pip install requests and everything is working now.
Reply
#4
Hi!

According to this:

(Nov-03-2019, 03:48 AM)ziggyztz Wrote: The mylibrary starts with these imports if it's relevant:
import py_game
import threading
import enum
import time
import requests
import datetime

and the last lines of your error message:

(Nov-03-2019, 02:40 AM)ziggyztz Wrote:
Error:
import requests ModuleNotFoundError: No module named 'requests'

I would say that either you haven't installed the module 'requests' on your version of python or that you have more than one version of python installed.

To see what version of python you have installed, you can type python -V in your Windows command prompt (not sure if you are using Mac).

To install the module 'requests' in the version of python you are running, type pip install requests in your Windows command prompt.

Another thing that comes to mind is that according to the message from your link, it seems that it could be related to python 3.8 as I think I've read that some people are having trouble trying to run some modules on it.

All the best,

P.S.:

Great! It seems that you worked it out!

All the best,
newbieAuggie2019

"That's been one of my mantras - focus and simplicity. Simple can be harder than complex: You have to work hard to get your thinking clean to make it simple. But it's worth it in the end because once you get there, you can move mountains."
Steve Jobs
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Are there errors in the code for my coin toss systems? Matlibplot is too perfect . Coolkat 0 342 Nov-13-2023, 11:54 AM
Last Post: Coolkat
  My code won't say Player wins or computer wins. No errors. its_a_meLuigi64 2 1,585 Dec-01-2021, 04:43 PM
Last Post: its_a_meLuigi64
  Rmarkdown opened by python code - errors Rav013 0 2,048 Apr-27-2021, 03:13 PM
Last Post: Rav013
  [split] Kera Getting errors when following code example Image classification from scratch hobbyist 3 4,546 Apr-13-2021, 01:26 PM
Last Post: amirian
  2 errors in code numbnumb54 2 1,971 Jul-24-2020, 02:28 PM
Last Post: Marbelous
  Code errors rhyjom 0 1,432 Jun-21-2020, 04:50 PM
Last Post: rhyjom
  Errors in code coolcassie 2 2,057 Dec-03-2019, 12:10 AM
Last Post: coolcassie
  errors in code sylvie1987100 3 2,245 Sep-11-2019, 12:54 PM
Last Post: sylvie1987100
  Decorator toy code throws syntax errors kevinxhi 3 3,520 Sep-04-2017, 03:01 AM
Last Post: kevinxhi

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020