How to run python script with library inside Kernell terminal? - python

I'm trying to run python script from terminal, but it's giving me error.
I already installed from linux terminal library sympy 'pip install sympy'. But still it doesn't work
This error i get when trying to run python script file.
Traceback (most recent call last):
File "script.py", line 2, in <module>
from sympy import symbols, diff
ModuleNotFoundError: No module named 'sympy'

Are you using two versions of Python?
python3.x uses pip3, and python2.x uses pip
1) Install pip3 on your system.
sudo apt install python3-pip
2) Install sympy by running
pip3 install sympy
3) Open python3 shell (run "python3" on your terminal) and import the necessary libraries
from sympy import symbols, diff

Related

Trying to setup nfcpy, Returns "ModuleNotFoundError: No module named 'ndef'"

I am trying to setup a PN532_NFC_HAT on a Raspberry Pi with nfcpy but I am having problems with modules.
What I have done so far:
I have installed nfcpy on my Raspberry Pi by simply doing this in the terminal.
$ pip install -U nfcpy
And I have verified the installation with this command
$ python -m nfc --search-tty
And so far it works, nfcpy can find my NFC Reader
Then I have cloned the examples from github
with the command
pi#raspberrypi: git clone https://github.com/nfcpy/nfcpy.git
and entered the examples-folder
pi#raspberrypi:~/nfcpy/examples $
What happens:
nfcpy has some example programs but when I try to run them they return various errors.
If I for an example run this command on one of the examples, Tagtool.py
python3 tagtool.py
I get this
Traceback (most recent call last):
File "tagtool.py", line 29, in <module>
import ndef
ModuleNotFoundError: No module named 'ndef'
Other examples return errors about not finding the module named nfc.
What am I doing wrong?
Please try below ↓
pip uninstall nfcpy
pip3 install nfcpy
or
sudo pip3 install nfcpy

Python cannot import scipy

I have Python 3.7.3 installed and installed numpy, scipy via pip (cmd -> python -m pip install --user numpy scipy) and am able to import numpy, scipy if I use an admin command prompt to import both numpy and scipy. However, if I don't use an admin cmd prompt, or try to import scipy from the Python shell, I receive traceback errors like the following:
>>> import numpy
>>> import scipy
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
import scipy
ModuleNotFoundError: No module named 'scipy'
Does this traceback error come from not installing scipy in a certain way? Thanks for the help in advance.
When doing checking pip and python versions in cmd, here's my output:
pip --version
pip 19.1 from c:\program files\python37\lib\site-packages\pip (python 3.7)
python --version
Python 3.7.3
Add the location of your python scripts to the Path in Environment Variables.
C:\Users\User_Name\AppData\Roaming\Python\Python37\Scripts
You mentioned that you've already installed the packages. And the packages are stored in the site-packages file inside Python37 folder. So the error must be because you didn't add these to the path.

Error Python PlaySound No module named 'gi'

when I request using "playsound" library for Python to play the audio
file .mp3 it returns me the following error:
Code:
import playsound
playsound.playsound("test.mp3")
Error:
Traceback (most recent call last):
File "/home/enzoportela/PycharmProjects/SoftwareRover2018.2/SoftRover/I.A Rover(2018.2).py", line 25, in <module>
playsound.playsound("test.mp3")
File "/home/enzoportela/anaconda3/envs/SoftwareRover2018.2/lib/python3.6 /site-packages/playsound.py", line 91, in _playsoundNix
import gi
ModuleNotFoundError: No module named 'gi'
The most simple way is the vext approach.
pip install vext
pip install vext.gi
Reference:
How do I install python3-gi within virtualenv?
It seems like you are using an anaconda environment. I also faced this issue and fixed it by doing the following:
First, create a symlink to gi module in your system Python. For me, the command is as follows:
ln -s /usr/lib/python3/dist-packages/gi/ /home/USERNAME/miniconda3/lib/python3.7/site-packages/
Then, open the directory:
cd /home/USERNAME/miniconda3/lib/python3.7/site-packages/gi/
and run the following commands:
sudo cp _gi.cpython-35m-x86_64-linux-gnu.so _gi.cpython-37m-x86_64-linux-gnu.so
sudo cp _gi_cairo.cpython-35m-x86_64-linux-gnu.so _gi_cairo.cpython-37m-x86_64-linux-gnu.so
My system Python is 3.5 and miniconda Python is 3.7. Your versions may differ from mine, so take care of that in the commands above (-35m- and -37m-).
Method obtained from askubuntu

python script that came with program doesn't seem to find the program module

I just installed Gubbins using their homebrew instructions. Everything seemed to go smoothly and gubbins is now in /usr/local/Cellar/gubbins/1.1.1/bin/gubbins. I'm supposed to be able to use it by running their script run_gubbins.py and giving it an input file. But I get the following error:
>$ /usr/local/Cellar/gubbins/1.1.1/usr/bin/run_gubbins.py test.fasta
Traceback (most recent call last):
File "/usr/local/Cellar/gubbins/1.1.1/usr/bin/run_gubbins.py", line 25, in <module>
from gubbins import common
ImportError: No module named gubbins
Looking inside the run_gubbins.py script I see that the first things it does is
import sys
sys.path.append(".")
import argparse
from gubbins import common
So what might be happening? How come the script within a program package is not recognizing the program it came with? Is there anything I can do to fix this? Thank you so much.
Install homebrew from brew.sh
Open a terminal and enter these commands
curl https://bootstrap.pypa.io/ez_setup.py | python - --user
export PATH=~/Library/Python/2.7/bin:${PATH}
easy_install pip
pip install --user dendropy
pip install --user biopython
pip install --user reportlab
brew tap homebrew/science
brew install http://sanger-pathogens.github.io/gubbins/fastml.rb
brew install http://sanger-pathogens.github.io/gubbins/gubbins.rb

python module for libnet in Opensuse

I have tried to run an Python program in my Opensuse OS this Program used libnet and pcap.
import queue
import sys
import socket
import libnet
from libnet.constants import *
import pcap
I have installed libnet-devel but when i run the program i recieve the folowing message.
Traceback (most recent call last):
File "example.py", line 9, in <module>
import libnet
ImportError: No module named libnet
I have tried with different Python version, How can i solve this Problem?
using the system python (the one in /usr/bin/python):
make sure that python-pip is installed via yast
download pylibnet from http://sourceforge.net/projects/pylibnet/
install pylibnet with the command
sudo pip install ./pylibnet-3.0-beta-rc1.tar.gz
there does not seem to be a version of pylibnet packaged and available through yast, which is why you need to install one using pip (which is a program for installing python packages).
libnet-devel only installs the c library - the above installs the python library.
[edit: forgot the "install" in the pip command; added download instructions]

Categories

Resources