Python Forum
getting an import statement to work in my program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
getting an import statement to work in my program
#1
I have installed PyCharm as my python IDE.

Previously, I (think) I installed a module pygame that has USB joystick interfaces.

In my program,I want to insert the import statement but am having errors.

I have inserted import pygame and get a module not found error.
so, I know the directory where pygame was installed.. C:/users/barry

so I am trying import C:/users/barry and this doesn't work.

What am I doing wrong??
I have tried c\users\barry\pygame.py and a few other attempts so how do I get pygame imported?

Thanks
Reply
#2
Did you read my last post where i try to explain how this work?
So to to add some info will install pygame and test that it work,all from cmd.
# Test python
C:\>python -V
Python 3.9.5

# Test pip
C:\>pip -V
pip 21.2.4 from c:\python39\lib\site-packages\pip (python 3.9)

# Install
C:\>pip install pygame --upgrade
Collecting pygame
  Downloading pygame-2.1.0-cp39-cp39-win_amd64.whl (4.8 MB)
     |████████████████████████████████| 4.8 MB 1.3 MB/s
Installing collected packages: pygame
Successfully installed pygame-2.1.0

# Test that it work
C:\>python
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pygame
pygame 2.1.0 (SDL 2.0.16, Python 3.9.5)
Hello from the pygame community. https://www.pygame.org/contribute.html
>>>
>>> pygame.__version__
'2.1.0'
>>> exit()

C:\>
So when all work from command line in Configure a Python interpreter choose same version as interpreter,
so the root path that pip -V show,eg for me c:\python39 for you it will shown and other path.
Then will Pygame work in PyCharm.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Can't get a new program to work jpotter0 2 945 Nov-28-2022, 03:40 AM
Last Post: jpotter0
  Cryptic Error with import statement Led_Zeppelin 2 2,479 Jan-11-2022, 01:13 PM
Last Post: Led_Zeppelin
  Why doesn't this print statement work? stylingpat 10 5,591 Mar-23-2021, 07:54 PM
Last Post: buran
  import statement in a virtual environment leodavinci1990 1 2,298 Mar-04-2021, 12:57 AM
Last Post: snippsat
  Does "import xlrd" work in Thonny? cnutakor 3 2,947 Apr-30-2020, 12:41 AM
Last Post: Larz60+
  import scalalib package doesn't work manu_brighter 2 2,840 Apr-17-2020, 06:36 PM
Last Post: snippsat
  return statement will not work TheTechRobo 2 2,588 Mar-30-2020, 06:22 PM
Last Post: TheTechRobo
  [split] import PIL dont work vedansh 1 2,048 Mar-29-2020, 10:00 AM
Last Post: Larz60+
  Newbie to Python Why does this if statement not work? Wrightys99 5 2,540 Mar-26-2020, 12:04 PM
Last Post: buran
  import PIL dont work rodink 14 12,643 Feb-22-2020, 08:48 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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