Missing numpy while running other external python script - python

I am trying to run a python script from python script.
I tried to run it like this:
os.system("python /opt/mycroft/skills/useridentification-skill/speakerIdentificationProgram/scoring.py")
Then I tried to import the file like this:
import sys
sys.path.append("/opt/mycroft/skills/useridentification-skill/speakerIdentificationProgram")
from scoring import get_id_result
they both returned this error:
File "/opt/mycroft/skills/useridentification-skill/__init__.py", line 9, in <module>
from scoring import get_id_result
File "/opt/mycroft/skills/useridentification-skill/speakerIdentificationProgram/scoring.py", line 2, in <module>
import numpy
ImportError: No module named 'numpy'

just try pip install numpy in your terminal. this will remove error

I think you are using numpy module in scoring.py but you have not installed numpy in your virtual environment.
Use "pip install numpy" after activating your virtualenv.

I assume you followed this to add skills, if so it should install numpy if the skill actually required it
https://mycroft-ai.gitbook.io/docs/mycroft-technologies/mycroft-core/msm
Ref - https://github.com/MycroftAI/documentation/issues/143
Otherwise, you should be using
mycroft-pip install numpy
And you should be source to activate the mycroft venv, and then use the Python command to run your script

Use Panda libraries for data manipulation and file access.
https://www.learnpython.org/en/Pandas_Basics

Related

How to run the python webapp using flask & anaconda from vscode?

I have installed Anaconda-Package, Flask, Pip & Vscode. I am currently running the development project on localhost using "pipenv shell" command then "flask run" command in vscode.
It works well on http://127.0.0.1:5000/ for simple webapp. But I want to display the prediction charts & tables on a webpage using pandas, numpy etc.
So, When I try to import
import pandas as pd
import numpy as np
It displays this ->
flask.cli.NoAppException
flask.cli.NoAppException: While importing "app", an ImportError was raised:
Traceback (most recent call last):
File "c:\users\mdev\.virtualenvs\flask_md_project-itylmdvv\lib\site-packages\flask\cli.py", line 240, in locate_app
__import__(module_name)
File "D:\flask_md_project\app.py", line 4, in <module>
import numpy as np
ModuleNotFoundError: No module named 'numpy'
above error as image
How do I use pandas,numpy,matplotlib etc from anaconda package along with flask through vscode for my python webapp ? Please help 🙏
According to the information you provided, the modules "pandas" and "numpy" are not installed in the Python environment you are currently using.
When we use the conda environment in VS Code, we use it as a python environment. Therefore, in this environment we need to install the module and then use this module. Usually, the module storage location of conda environment is (for example, base conda environment): "\users\username\anaconda3\lib\site-packages".
We can use the command "pip show pandas" in the VS Code terminal to check the installation location of the module:
For more information about flask in VS Code, you could refer to: Flask Tutorial in Visual Studio Code.
Install numpy on anaconda by running;
conda install numpy

ImportError: cannot import name '_ccallback_c'

Initially I was getting this error (No Module name was found scipy) So I installed a Scipy wheel file. Now I don't get the same error any more but I get cannot import name "_ccallback_c".
The error seems to be triggered at the fourth line of code. I have done my research and saw that other people suggested to try an environment such as Anaconda. I have seen it work on idle, and that solution isn't ideal for me.
Traceback:
Traceback (most recent call last):
File "C:\Users\joesh\Desktop\Python\Machine Learning\1st tutorial.py", line 4, in <module>
from sklearn import preprocessing, cross_validation, svm
File "C:\Users\joesh\Desktop\Python\lib\site-packages\sklearn\__init__.py", line 134, in <module>
from .base import clone
File "C:\Users\joesh\Desktop\Python\lib\site-packages\sklearn\base.py", line 10, in <module>
from scipy import sparse
File "C:\Users\joesh\Desktop\Python\lib\site-packages\scipy\__init__.py", line 118, in <module>
from scipy._lib._ccallback import LowLevelCallable
File "C:\Users\joesh\Desktop\Python\lib\site-packages\scipy\_lib\_ccallback.py", line 1, in <module>
from . import _ccallback_c
ImportError: cannot import name '_ccallback_c'
And the code:
import pandas as pd
import quandl, math
import numpy as np
from sklearn import preprocessing, cross_validation, svm
from sklearn.linear_model import LinearRegression
I had the same error on USING Anaconda, so I am not sure if using it would make any difference.
I solved it by just uninstalling scipy and re-installing it using pip:
pip uninstall scipy
you'll get this message:
Uninstalling scipy-1.1.0: Would remove:
c:\users\thesh\appdata\local\programs\python\python36-32\lib\site-packages\scipy-1.1.0.dist-info*
c:\users\thesh\appdata\local\programs\python\python36-32\lib\site-packages\scipy*
Proceed (y/n)?
press y, and after pip is done, type:
pip install scipy
Having just moved to MSVS 2017 for Python (ML) development, I encountered this and other errors related to missing modules. The problem (and all related problems like it) has a frustratingly simple solution: when I originally started coding in Python, I installed everything from the command line - apparently, MSVS 2017 doesn't "see" those installations (and, in fact, they sometimes conflict, since the underlying python may be tapping older libs); so, the solution is to:
Use the command line version of 'pip uninstall ...' where '...' is the library having missing dependencies (scipy, in this case). Then, in the MSVS 2017 command line on the Python environment window (usually, top right in the default display configuration), reload the library (in this case, typing 'scipy' will format a command line for execution [in the list control below the command textbox]) that will read something like 'pip install scipy' (or whatever library needs to be reinstalled for MSVS).
You may have to do this for many (or all) of your previous Python package installations where these missing module errors persist.
Can be resolved, by uninstalling and reinstalling using pip on Anaconda Prompt:
pip uninstall scipy
After the uninstall, you can reinstall with:
pip install scipy
When you installed scipy with pip in a Python version 3.6 and later try to run your code with Python 3.7 you will encounter this problem. So one solution is to uninstall scipy
pip3 uninstall scipy
and reinstall it (using an environment with Python 3.7):
pip3 install scipy
This will make sure that the installed version of scipy is compatible with your version of Python.
PS: When you updated Python from Python 3.6 to Python 3.7 it might be necessary to also reinstall pip, so that pip will use the correct version of Python internally.
I ran into this when I was following these instructions on how to use a virtual environment to use the pre-built version of SciPy. The simplest solution for me was to simply comment out from . import _ccallback_c under scipy\_lib\_ccallback.py.
I first had the error with scipy. So I ran the command python -m pip install -user numpy scipy matplotlib ipython jupyter pandas sympy noseand it worked perfectly. I was installing everything with pip, so I decided to use Anaconda. I installed and checked to add to the PATH. From there, the same code that was executed before normally stopped working and displays the error similar to that of the question. I uninstalled Anaconda and it is now working again.
Erro:
$ winpty python ia.py
Traceback (most recent call last):
File "ia.py", line 11, in <module>
from sklearn import tree #importando a biblioteca e a árvore p/ o classifica
dor
File "C:\Users\ferna\Anaconda3\lib\site-packages\sklearn\__init__.py", line 13
4, in <module>
from .base import clone
File "C:\Users\ferna\Anaconda3\lib\site-packages\sklearn\base.py", line 11, in
<module>
from scipy import sparse
File "C:\Users\ferna\AppData\Roaming\Python\Python36\site-packages\scipy\__ini
t__.py", line 118, in <module>
from scipy._lib._ccallback import LowLevelCallable
File "C:\Users\ferna\AppData\Roaming\Python\Python36\site-packages\scipy\_lib\
_ccallback.py", line 1, in <module>
from . import _ccallback_c
ImportError: cannot import name '_ccallback_c'
Código:
from sklearn import tree #importando a biblioteca e a árvore p/ o classificador
#COLLLECT TRAINING DATA
features = [[140,1],[130,1],[150,0],[170,0]]
labels = [0,0,1,1]
# TRAIN CLASSIFIER
clf = tree.DecisionTreeClassifier() #Classificador
clf = clf.fit(features, labels) #algoritmo de decisão p/ encontrar padrões
#MAKE PREDICTIONS
print(clf.predict([[160, 0]])) #entrada de dados para o tratamento
Try this:
python -m pip install --upgrade scipy
After digging in, to give the full background on this, first of all SciPy relies on having NumPy already installed. The SciPy wheel's setup.py file uses NumPy functionality to configure and install the wheel.
SciPy setup.py:
...
if __name__ == '__main__':
from numpy.distutils.core import setup
setup(**configuration(top_path='').todict())
Secondly, when just trying to use the wheel, if you run into this error, you can see after inspecting the wheel's files that the reason is the binary wheels have a naming convention where the shared object file, here it's called _ccallback_c.so, is instead named based on the architecture that the binary wheel supports. When trying to import the shared object by file name in /_lib/_ccallback.py it can't find it, hence this error (line 1 in /_lib/_ccallback.py) because, instead of being named _ccallback_c.so it's called _ccallback_c.cpython-36m-x86_64-linux-gnu.so or another architecture variation:
from . import _ccallback_c
These file names seem to be an artifact of libraries that are using Cython and Cython's adherence to PEP 3149 (ABI version tagged .so files). But the easiest fix is to change the .whl extension to .zip and rename all those relevant .so files to not contain the architecture snippet. Then change .zip -> .whl and it should be good to go unless it's the wrong architecture for the platform you're using, in which case you need to download the appropriate platform wheel for your platform.

Not able to import module after installing using pip

Im trying to import a module called geoip2 from pypi into python it is not included in its standard libraries.
I open command prompt and type:
pip install geoip2
The command prompt returns
Successfully installed geoip2-2.4.2
After it is installed I try importing it using IDLE:
import geoip2.webservice
which returns the error:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
import geoip2.webservice
ImportError: No module named 'geoip2'
Although it is installed already I cannot use it. How can i prevent this? Take note that I use python 3.6
May be you have two different version of Python installed. Try opening IDLE using the Python version where you have installed geoip.
Instead of:
import geoip2.webservice
Try doing:
import geoip2
from geoip2 import webservice
Since geoip2.webservice is not installed, geopip2 is and .webservice is an function object of that module.
Further, you can avoid typing geoip2.webservice every time by doing:
import geoip2
from geoip2 import webservice as gws
Then anytime you want to run the .webservice function, you can just use gws.
Alternatively:
Just do:
import geoip2
Then in your script you can call it:
geoip2.webservice(#do stuff here or however you call the function)

Python third party Module global import

i'm currently into learning a bit of python and i want to import the paperclip third party module into my python file.
Yes, i already installed the pyperclip module with
pip install pyperclip.
if i create a file on my desktop, i get an error which says
Traceback (most recent call last):
File "test.py", line 1, in <module>
import pyperclip
ImportError: No module named pyperclip
However if i put the test.py in my python folder, it runs.
The question now is, is there a way to make all my installed modules available on a global scope ? I just want to have my file e.g. on my Desktop and run it without having import issues.
Thank you.
Greetings
Edit: I'm working on a Mac, maybe this leads to the problem
Found the problem.
The pip installautomatically used pip3.5 install
whereas python test.pydidn't use python3.5 test.py
Thank you #Bakurìu
Is there a way i can define python3.5as python?
You can do this :
pip3.5 install paperclip
pyperclip is install but not paperclip

Not able to import netCDF4 to Spyder (Anaconda, OSX10.10)

I'm trying to learn to use Python for scientific analyses (in particular of large NETCDF files), and have installed Anaconda on my MacBookPro OSX10.10. I'm trying to use the Spyder IDE interface, but am stalled by errors with getting the netCDF4 package to work properly.
I need to use the netCDF4 package which I installed using:
conda install netcdf4
First I couldn't get any of the Anaconda packages to import in either Spyder or Python run directly in the terminal, but tried running:
export PATH=~/anaconda/bin:$PATH
Now I get all Anaconda pre-installed packages to work in Spyder (no error when I try the import command), EXCEPT for netCDF 4 which still comes up with the following error:
import netCDF4
Traceback (most recent call last):
File "<ipython-input-7-f731da2de255>", line 1, in <module>
import netCDF4
File "/Users/eriko/anaconda/lib/python2.7/site-packages/netCDF4/__init__.py", line 6, in <module>
from ._netCDF4 import (__version__, __netcdf4libversion__, __hdf5libversion__,
ImportError: cannot import name __netcdf4libversion__
However, netCDF4 imports without any error in the terminal version of Python?
The 'Code Analysis' in Spyder flags the following error in scripts where I added the import netCDF4 command:
'netCDF4' imported but unused
E402 module level import not at top of the file
W292 no newline at the end of file
I've spent too many hour Googling without finding a solution to this, so I hope the Stackoverflow community can help.

Categories

Resources