I not able to import pygame module in linux - python

[![this is the image for reference
I am not able to use the init function.
please solve this issue.
]1]1

You named your script pygame.py, that is a very bad idea because it shadows the real pygame module, change the name of your script and it should work fine.

Related

Using a function from a built-in module in your own module - Python

I'm new with Python and new on Stackoverflow, so please let me know if this question should be posted somewhere else or you need any other info :). But I hope someone can help me out with what seems to be a rather simple mistake...
I'm working with Python in Jupyter Notebook and am trying to create my own module with some selfmade functions/loops that I often use. However, when I try to some of the functions from my module, I get an error related to the import of the built-in module that is used in my own module.
The way I created my own module was by:
creating different blocks of code in a notebook and downloading it
as 'Functions.py' file.
saving this Functions.py file in the folder that i'm currently working in (with another notebook file)
in my current notebook file (where i'm doing my analysis), I import my module with 'import Functions'.
So far, the import of my own module seems to work. However, some of my self-made functions use functions from built-in modules. E.g. my plot_lines() function uses math.ceil() somewhere in the code. Therefore, I imported 'math' in my analysis notebook as well. But when I try to run the function plot_lines() in my notebook, I get the error "NameError: name 'math' is not defined".
I tried to solve this error by adding the code 'import math' to the function in my module as well, but this did not resolve the issue.
So my question is: how can I use functions from built-in Python modules in my own modules?
Thanks so much in advance for any help!
If anyone encounters the same issue:
add 'import math' to your own module.
Make sure that you actually reload your adjusted module, e.g. by restarting your kernell!

PyCharm- AttributeError: module 'numpy' has no attribute 'arange'

I've just installed a NumPy in my computer and everything in Python consol is OK- https://i.stack.imgur.com/DFC4O.png
but in every interpreter i have the same problem:
https://i.stack.imgur.com/ANxG2.png
Thanks for help!
You called your program file numpy.py so the file is trying to import itself rather than the real numpy module. Call your file something like numpy_test.py instead.
Be sure you use the correct Python path.
If other attributes works well?
you should check this link first Why does PyCharm give unresolved reference errors on some Numpy imports?

Can't Install Vect2D

I'm following a pygame tutorial, and in it, you need to use multiple different modules. I was able to download all of them, except this one called Vec2D. When I try to run it in command prompt, it gives me this:
This is really weird because it gives no output - the module isn't set up and I don't get an error. When I try to test it later, it doesn't work. Does anyone know how to help me?
The instructor has written his own module, called vec2d_jdm.py containing a class called Vec2D.
You don't need to install it, just make sure that the file vec2d_jdm.py is in the same folder as the code you're running and from vec2d_jdm import Vec2D at the top of your code where you import everything else (such as pygame I imagine).

How to create python Ply lex passing a module

I'm trying to use a Logo Language Compiler that uses Ply into the Unity3D environment for an Open Source project https://github.com/ssouzawallace/blocks-programming.
To do so I am using IronPython that is a Python interpreter running in .NET (I need this to run in Uinty3D). There is a bug in IronPython and i found others with the same issue related to the traceback of python script execution.
In resume if I run the Logo Compiler using the official Python interpreter everything goes OK. But in IronPython, when the code pass trough the get_caller_module_dic method it cannot find my pyLex stuff because it cannot reach the second frame level.
In order to resolve the problem I am wondering to pass the proper object or module to the method:
def lex(module=None,object=None,debug=0,optimize=0,lextab="lextab",reflags=0,nowarn=0,outputdir="", debuglog=None, errorlog=None):
But I don't know how to do this.
Someone know what can I do?
Thank you very much in advance
Found solution here Python: How do I get a reference to a module inside the module itself?
Now I pass the entire script as a module instead hoping the lex and yacc script find my module using the traceback.
Using
import sys
current_module = sys.modules[__name__]

Annoying Python Image.pixel method issue

so I'm just trying to learn how to use the Image module and for some reason PyCharm won't recognize the Image.Pixel method, even after I've imported the Image module. An easy question, I'm sure, but What am I doing wrong here? (I've installed PIL)
from PIL import Image
p = Image.Pixel(45, 76, 200)
print(p.getRed())
PyCharm tells me 'ImportError: No module named 'Pixel', but from what I've read here (http://interactivepython.org/courselib/static/thinkcspy/MoreAboutIteration/2DimensionalIterationImageProcessing.html#image-objects), I don't really see why this isn't working...
thanks in advance guys.

Categories

Resources