I can't import pygame inside pycharm - python

I can't import pygame inside pycharm.
I've been using Linux Mint 19, Anaconda 3, Pycharm 2019.3.1.
I've created a conda environment and install pygame: conda install pygame -c cogsci
Then I ran (my_env) tiago#tiago-XPS-8700:~$ python3 mycode.py. And I got the following error:
teste.py:3: RuntimeWarning: use mixer: libSDL_mixer-1.2.so.0: cannot
open shared object file: No such file or directory (ImportError:
libSDL_mixer-1.2.so.0: cannot open shared object file: No such file or
directory) pygame.mixer.music.load('bat.mp3') Traceback (most recent
call last): File "teste.py", line 3, in
pygame.mixer.music.load('bat.mp3') File "/home/tiago/anaconda3/envs/pycharm/lib/python3.5/site-packages/pygame/init.py",
line 105, in getattr
raise NotImplementedError(MissingPygameModule) NotImplementedError: mixer module not available (ImportError:
libSDL_mixer-1.2.so.0: cannot open shared object file: No such file or
directory)
After reading some blog at internet I installed sudo apt install libsdl-mixer1.2.
After that if I run (my_env) tiago#tiago-XPS-8700:~$ python3 mycode.py at Linux terminal at my conda environment, my code run successfully.
But If I try to run the same code inside Pycharm I get the following error:
/home/tiago/anaconda3/envs/pycharm/bin/python
/home/tiago/Documentos/PYTHON/cursoemvideo/exercicios/ex_021.py
Traceback (most recent call last): File
"/home/tiago/Documentos/PYTHON/cursoemvideo/exercicios/ex_021.py",
line 3, in
import pygame File "/home/tiago/anaconda3/envs/pycharm/lib/python3.5/site-packages/pygame/init.py",
line 133, in
from pygame.base import * ImportError: libSDL-1.2.so.0: cannot open shared object file: No such file or directory
Process finished with exit code 1
What am I missing?

In conda environment they have pre installed packages and libraries which u can easily use by importing them but in pycharm u additionally need to intall that package so that u can use it in pycharm

Inspired by this questions Tensorflow and Pycharm, I ran Pychram from the Linux Terminal at my conda environment and it worked! If I run Pycharm from Linux Mint Menu I still can't import pygame.
Addicionally, I inserted the following statement at my .bashrc so that I can run pycharm from anywhere in the Linux Terminal.
# Open bashrc to edit
nano .bashrc
# Add the comand line below to the end of file
# You should adapt to your path to "pycharm.sh', mine is "/opt/pycharm-community-anaconda-2019.1.3/bin". In another computer I found it at "/var/lib/flatpak/app/com.jetbrains.PyCharm-Community/current/active/files/pycharm/bin"
export PATH=$PATH:/opt/pycharm-community-anaconda-2019.1.3/bin
# Then close the terminal and reopen it in order to the modifications in .bashrc take effect
# At terminal you run
pycharm.sh

Related

ImportError: libgssapi_krb5.so.2: cannot open shared object file: No such file or directory

I have been getting the following error when trying to run one one of my Python Programs
Traceback (most recent call last):
File "/Path/to/program/Main.py", line 7, in <module>
from src.ui.python import Home
File "/Path/to/program/src/ui/python/Home.py", line 13, in <module>
from PyQt5 import QtWebEngineWidgets
ImportError: libgssapi_krb5.so.2: cannot open shared object file: No such file or directory
I am currently using a python virtual environment and I have made sure all the proper PyQt5 packages are installed. After a bit more research I discovered that libgssapi_krb5 is a Ubuntu system program. I have used sudo apt -y install libgssapi-krb5-2 and sudo apt -y install libgssapi-krb5-2:i386. And the program is already installed on my system. I have tried to purge and remove my file but cannot because “This operation is not permitted because it will break the system.”
Here are some other sources I have found but their solutions have not worked for me:
ImportError: libGL.so.1: cannot open shared object file: No such file or directory: HyperV Docker
https://jobs.goyun.info/2020/01/how-to-fix-importerror-libgssapikrb5so2.html
https://zoomadmin.com/HowToInstall/UbuntuPackage/libgssapi-krb5-2
I am not sure what else I can do fix this issue so any help would be appreciated.
one man's experience, but installing rsyslog-gssapi worked for me
I'm on void linux, linux version 5.15.24_1

Error while running Package in Command prompt , No module found

I have created a package named as patterns along with test.py,
test.py has the following code lines:
from patterns.shapes import *
square()
[Module Error]
I have copied the test.py file to the same location F:, where I trying to run via command prompt.
To gain access to this package from any location I have installed it using pip install . in the windows command prompt, which was successful, but when I try to access the file test.py I am getting the error as below :
F:\>py test.py
Traceback (most recent call last):
File "test.py", line 1, in <module>
from patterns.shapes import *
ModuleNotFoundError: No module named 'patterns'
My package folder is stored in a different drive.
While working on a python project, one must always work in a virtual environment. Please check if you have your virtual environment activated. If not, then follow the steps:
cd your_working_directory
virtualenv environment_name where environment_name can be any name you want.
environment_name/Scripts/activate if on Windows
Or environment_name/bin/activate if on MacOS
Then after activating the environment you can install all the dependencies using pip. i.e pip install patterns

python virtualenv from terminal not working but working from pycharm

Python3 showing error while trying to create a new virtual environment from terminal using
virtualenv name_goes_here
with error,
Traceback (most recent call last):
File "/home/w3e/.local/bin/virtualenv", line 7, in
from virtualenv import main
ImportError: cannot import name 'main' from 'virtualenv' (/usr/lib/python3/dist-packages/virtualenv/init.py)
But it works when I do it from PyCharm > Settings > Project Interpreter > Add Python Interpreter
See the attached image below-
The command you were using doesn't exist.
Try this instead:
python3 -m venv your_venv
And activate it using:
source your_venv/Scripts/activate

Pycharm Terminal does not seem to use virtual environment

I have a venv setup with Python 3.7 with several packages installed. I installed them using the UI in settings and the scripts run fine.
However, when I go to the Terminal window and try to run my script there there, it gives me an error message saying "No module named xxxx".
Running python3 run_glue.py, it curiously gives me the following error:
sh-3.2$ python3 run_glue.py
Traceback (most recent call last):
File "run_glue.py", line 27, in <module>
import torch
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/torch/__init__.py", line 79, in <module>
from torch._C import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/torch/_C.cpython-36m-darwin.so, 9): Library not loaded: /usr/local/opt/libomp/lib/libomp.dylib
Referenced from: /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/torch/lib/libshm.dylib
Reason: image not found
It seems that it is looking at a python 3.6 environment despite my virtual environment being 3.7. I checked my settings and I dont see why it would be looking at the python 3.6 environment.
Any thoughts here?
You need to activate your environment first:
sh-3.2$ source path_of_your_venv/bin/activate
You should now see an (env) before your bash prompt:
(env) sh-3.2$
Then you can check if python3 is correctly referencing the environment by which python3.
Alternatively, execute python3 directly from within your environment:
./path_of_your_venv/bin/python3 run_glue.py.

Pylucene 4.9.0 Ubuntu 14.04 Installation ImportError

I've been trying to install Pylucene on my Mac for a little over a week, and have given up on that in favor of trying to install it with Ubuntu through a virtual machine. I thought the installation process had gone well, so I fired up Python in the terminal and tried to import lucene and received the following ImportError:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/parallels/anaconda/lib/python2.7/site-packages/lucene/__init__.py", line 7, in <module>
import _lucene
ImportError: libverify.so: cannot open shared object file: No such file or directory
So, it looks like there is a module _lucene that does not exist. But I thought this would have been part of what I had just installed? Any insight here would be appreciated.
I had to add extra paths to my LD_LIBRARY_PATH environment variable to get things working. The test here in the conda build script actually shows those variables.
export LD_LIBRARY_PATH=$PREFIX/lib:$PREFIX/jre/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$PREFIX/jre/lib/amd64:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$PREFIX/jre/lib/amd64/server:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$PREFIX/lib/python2.7/site-packages:$LD_LIBRARY_PATH
$PREFIX here is the path to the anaconda folder. I currently install miniconda at /usr/conda on my systems.

Categories