trouble importing autograd in python script - python

I'm trying to import autograd with the following line of code:
import autograd.numpy as np
However, I'm getting the following error when trying to run the script:
Traceback (most recent call last):
File "autograd.py", line 1, in <module>
import autograd.numpy as np
File "/home/hakon/Documents/FYS_STK4155/project2/code and plots/test/autograd.py", line 1, in <module>
import autograd.numpy as np
ModuleNotFoundError: No module named 'autograd.numpy'; 'autograd' is not a package
I've tried installing autograd through pip, pip3 and conda, but the error remains the same.

The problem is that your module (the one that you're running) has the same name that you're trying to import: autograd (.py). Try renaming your file and running it again.

aaossa's answer worked for me. If changing the module name that you are running doesn't work, please check if there is any other autograd(.py) that you created existing in your current directory. If so, you also need to change that file's name or delete it so that you can import "autograd".

Related

ModuleNotFoundError: No module named 'h2oaicore'

I am following the tutorial of driverless: Driverless AI Standalone Python Scoring Pipeline, you can check it in the following link:
http://docs.h2o.ai/driverless-ai/latest-stable/docs/userguide/scoring-standalone-python.html#tar-method-py
I am performing:
Running Python Scoring Process - Recommended
but, when running the last step:
DRIVERLESS_AI_LICENSE_KEY = "pastekey here" SCORING_PIPELINE_INSTALL_DEPENDENCIES = 0 /path/to/your/dai-env.sh ./run_example.sh
the following error happens:
Traceback (most recent call last): File "example.py", line 7, in
from scoring_h2oai_experiment_5fd7ff9c_b11a_11eb_b91f_0242ac110002 import Scorer File
"/usr/local/lib/python3.6/dist-packages/scoring_h2oai_experiment_5fd7ff9c_b11a_11eb_b91f_0242ac110002/init.py",
line 1, in
from .scorer import Scorer File "/usr/local/lib/python3.6/dist-packages/scoring_h2oai_experiment_5fd7ff9c_b11a_11eb_b91f_0242ac110002/scorer.py",
line 7, in
from h2oaicore import application_context
ModuleNotFoundError: No module named 'h2oaicore'
--
Hope you can help me, thanks in advance.
Apparently it doesn't find your h20aicore module. One brute force method to import it could be do the following in your python script:
import sys
import os
sys.path.append(os.path.abspath("path/to/module"))
or alternatively you should add it to your python path.
I agree with #BlackPhoenix's comment. It is looking for h2oaicore module. The DAI Python scoring pipeline comes with a h2oaicore .whl file. Check out the shell script, run_example.sh. It should contain steps about pip installing h2oaicore.

Error on calling a function from another file on python

I'm getting an error on importing a function from another file in python.
This is my file structure
In checkSpellings.py there's a function defined as spellchecker(tokenized_text) . And I'm trying to use it by importing it on main.py by following code
from checkSpellings import spellChecker
But it gives me an warning (red underline on top of both of checkSpellings(file name) and spellChecker(function name) in import code). This previously happened and I though this is purely an issue with intellisense . Because last time same thing happened (gave me the warning), but the code worked fine.
But now when I run the main.py it gives me an error saying
Traceback (most recent call last):
File "/home/pankaja/Documents/PycharmProjects/BookDigitizer/OCR_Correction/main.py", line 1, in <module>
from checkSpellings import spellChecker
ImportError: cannot import name 'spellChecker
How can I fix this ? What have I done wrong ?
IMPORTANT : Here I'm using python3.6 interpreter on an anaconda virtual environment. Might it be an issue ?
The function is spellchecker but you tried to import spellChecker.

Errors importing pyodbc

My background is Java/C++ and I'm very new to python. I'm trying to import pyodbc to my project which works alright if I do it via command line.
import odbc
However, when I try to do the same in pydev/eclipse, i get the following error which I cannot find a solution to. I suspect this may have something to do with Eclipse setup
Traceback (most recent call last):
File "C:\Users\a\workspace\TestPyProject\src\helloworld.py", line 2, in <module>
import pyodbc
File "C:\Users\a\AppData\Local\Continuum\Anaconda3\Lib\site-packages\sqlalchemy\dialects\mssql\pyodbc.py", line 105, in <module>
from .base import MSExecutionContext, MSDialect, VARBINARY
ImportError: attempted relative import with no known parent package
I'm really stuck here and any hints will be appreciated!
An incorrect library was imported into the External Libraries list of the project. After fixing it, the import is working.

ImportError: No module named vis (Python )?

Hello l tried to run my python code and the errors is:
Traceback (most recent call last):
File "/home/anelmad/Desktop/simulation/Theano-Tutorials-master/3_net.py", line 5, in <module>
from foxhound.utils.vis import grayscale_grid_vis, unit_scale
ImportError: No module named vis**
knowing that l have correctly installed foxhound.
import theano
from theano import tensor as T
import numpy as np
from load import mnist
from foxhound.utils.vis import grayscale_grid_vis, unit_scale
from scipy.misc import imsave
is Foxhound a scikit? if yes, it doe's not contains utils module. You can clone it on github https://github.com/IndicoDataSolutions/Foxhound
I have met with the same problem. from foxhound vis import grayscale_grid_vis is enough. And I just comment out the other part. And the program works well. It seems that the module is not used.

Python missing modules with Theano

i have installed theano a deep neural network library and am trying to run some examples, but it looks like the script cant find some of the modules. i tried setting path
export PYTHONPATH=/Library/Python/2.7/site-packages/theano
sys.path.append('/Library/Python/2.7/site-packages/theano')
but both are not working. I get this error. I see that the modules are properly installed in subdirectory of theano /Library/Python/2.7/site-packages/theano/tensor/.. but somehow python cant seem to find the modules
Please can someone help. I am using a mac.
$python theano_mnist.py
Traceback (most recent call last):
File "theano_mnist.py", line 45, in <module>
import theano
File "/Users/prabhubalakrishnan/Desktop/theano.py", line 6, in <module>
from theano.tensor.nnet import conv
ImportError: No module named tensor.nnet
There is an issue on Theano repository. As fast solution I have:
Opened the file "miniconda3/envs/YOUR_CONDA_ENV_NAME/lib/python3.4/site-packages/theano/tensor/signal/downsample.py"
change the import import pool in from . import pool
and it works!

Categories