Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Library error
#11
(Apr-29-2023, 08:35 PM)Axel_Erfurt Wrote: Run your project and you'll see it.
I've used the pre-made code from the documentation, but I'm getting an error when trying to run it.
print(server_addr)
^
IndentationError: expected an indented block after 'for' statement on line 1

here is the code i used
for server_addr in gs.query_master(r'\appid\730\white\1', max_servers=3):
...     print(server_addr)
buran write Apr-30-2023, 05:27 AM:
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.
Reply
#12
Can not have ... in code,this comes from when run code with interactive interpreter.
So like this.
for server_addr in gs.query_master(r'\appid\730\white\1', max_servers=3):
    print(server_addr)  
Your image show that Pycharm now use virtual environment,so that where stream is install.
Then most sure when run code that it use same project Python interpreter,or it will not find steam.
Look at PyChram Configure a Python interpreter
To make sure add this in your code.
import sys

print(sys.executable)
So this most point to same Path as Python Interpreter in your image.

I do not like that PyCharm make virtual environment bye default,as this cause a lot confusion for beginners.
I do not use PyCharm,and always use command line for install pip/virtual environment ...ect.
Just that we get these threads some time with PyCharm about confusion about Python interpreter.
Reply
#13
(Apr-30-2023, 09:16 AM)snippsat Wrote: Can not have ... in code,this comes from when run code with interactive interpreter.
So like this.
for server_addr in gs.query_master(r'\appid\730\white\1', max_servers=3):
    print(server_addr)  
Your image show that Pycharm now use virtual environment,so that where stream is install.
Then most sure when run code that it use same project Python interpreter,or it will not find steam.
Look at PyChram Configure a Python interpreter
To make sure add this in your code.
import sys

print(sys.executable)
So this most point to same Path as Python Interpreter in your image.

I do not like that PyCharm make virtual environment bye default,as this cause a lot confusion for beginners.
I do not use PyCharm,and always use command line for install pip/virtual environment ...ect.
Just that we get these threads some time with PyCharm about confusion about Python interpreter.
So my code should look like this?
import include
import steam
import sys
print(sys.executable)
for server_addr in gs.query_master(r'\appid\730\white\1', max_servers=3):
    print(server_addr)
I get this error when interpreting this code (the code is from the official documentation)
for server_addr in gs.query_master(r'\appid\730\white\1', max_servers=3):
                       ^^
NameError: name 'gs' is not defined
I don't really understand what should I change in my interpreter, should I download a different version of the interpreter?
Reply
#14
add to your imports

from steam import game_servers as gs
Reply
#15
(Apr-30-2023, 09:16 PM)M53RX1 Wrote: I don't really understand what should I change in my interpreter, should I download a different version of the interpreter?
No,is just that PyChram mange this for you.
Now this project you are using Configure a virtual environment
Then is like blank version of Python and all libraries use most be install to this virtual environment.

For a other project can choice your Os Python version,look at Configure a system interpreter.
You should also lean how command line works,like basic stuff like what python and pip version and Path the have.
Example with cmd.
# Python version 
C:\>python -V
Python 3.10.5

# pip version
C:\>pip -V
pip 23.0.1 from C:\python310\lib\site-packages\pip (python 3.10)

# Path to Python
C:\>where python
C:\python310\python.exe

# Example install something
C:\>pip install requests --upgrade
Requirement already satisfied: requests in c:\python310\lib\site-packages (2.28.1)
Collecting requests
  Downloading requests-2.29.0-py3-none-any.whl (62 kB)
.....
Successfully installed requests-2.29.0
So if i had use PyChram i could have choice path C:\python310\python.exe for Configure a system interpreter
Then would also Requests work as i have as you see i installed to my OS version of Python.
Reply


Forum Jump:

User Panel Messages

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