ImportError: No module named 'fig_code' - jupyter-notebook

I am using ipython notebook. I am using python 3.5 . I got No module named 'fig_code' error while running a program as written below.
#Code
from sklearn import neighbors, datasets
iris = datasets.load_iris()
X, y = iris.data, iris.target
knn = neighbors.KNeighborsClassifier(n_neighbors=5, weights='uniform')
knn.fit(X, y)
X_pred = [3, 5, 4, 2]
result = knn.predict([X_pred, ])
print(iris.target_names[result])
print(iris.target_names)
print(knn.predict_proba([X_pred, ]))
from fig_code import plot_iris_knn
plot_iris_knn()
The error I am getting is as follows
ImportError Traceback (most recent call last)
<ipython-input-3-e8dd8ed3c9cb> in <module>()
18 print(knn.predict_proba([X_pred, ]))
19
---> 20 from fig_code import plot_iris_knn
21 plot_iris_knn()
ImportError: No module named 'fig_code'
I tried to install fig_code by using 'pip install fig_code' but I am getting this error
"Could not find a version that satisfies the requirement fig_code (from versions: ) No matching distribution found for fig_code"
I have searched the error to resolve this issue but no use.
Can anyone help me resolve it?

Seems you are following 'fig_code' from Jake Vanderplas lecture from pyon2015 on sklearn.
Okay, coming straightway to your problem. go to the https://github.com/jakevdp/sklearn_pycon2015 and download/cloan it. In 'notebooks' you will find fig_code folder. save it in the folder where your script is ....Now you will able to call 'fig_code'....

fig_code refers to a folder supplementary to Jake VanderPlas's sklearn ipython notebooks.
Download the fig_code module from Github by typing the following command in Terminal:
svn checkout https://github.com/jakevdp/sklearn_pycon2015/trunk/notebooks/fig_code
A folder named 'fig_code' will appear in your home directory.
Move 'fig_code' to the folder where your script is.

Related

Failed to execute script due to unhandled exception: No module named ttkwidgets

I created an executable from a py file that used ttkwidgets
import tkinter as tk
import work_logger_database
from ttkwidgets.autocomplete import AutocompleteEntry
root = tk.Tk()
root.geometry('600x300')
items = work_logger_database.show_all()
stored_projects_list = list(set([items[i][2] for i in range(len(items))]))
#or:
#example_list = ['Hello', 'World']
project_entry = AutocompleteEntry(root, completevalues=stored_projects_list)
project_entry.grid(column=0, row=1, sticky='W')
root.mainloop()
and when I open the exe I get what is shown in this image
I also got a warning:
WARNING: Several hooks defined for module 'numpy'. Please take care they do not conflict.
I'm not sure if that's relevant
I tried a solution in creating the exe that didn't work:
pyinstaller work_logger.py --onefile -w --hidden-import=ttkwidgets --hidden-import=ttkwidgets.autocomplete
I also tried:
pyinstaller work_logger.py --onefile -w --hidden-import=ttkwidgets
Had the same ModuleNotFoundError: 'ttkwidgets' creating an executable of one of my scripts.
Worked after (re-)installing ttkwidgets on my system:
pip install ttkwidgets

Can't import cv2 (opencv-python) on apple M1

I want to run a script on python that requires opencv-python. I'm working on a Mac. Based on other questions/answers here it seems the issue might be related to the M1 chip
I installed the latest version using the pip install command. Using pip list , I see that the installation was successful [opencv-python version 4.5.5]
now I encounter this error when I try to import cv2 on python3:
Traceback (most recent call last):
File "< stdin >", line 1, in < module >
ImportError: dlopen(/Users/maha/opt/anaconda3/lib/python3.9/site-packages/cv2.cpython-39-darwin.so, 0x0002): Library not loaded: #rpath/liblapack.3.dylib
Referenced from: /Users/maha/opt/anaconda3/lib/libopencv_core.4.5.5.dylib
Reason: tried: '/Users/maha/opt/anaconda3/lib/liblapack.3.dylib' (no such file), '/Users/maha/opt/anaconda3/lib/liblapack.3.dylib' (no such file), '/Users/maha/opt/anaconda3/lib/python3.9/site-packages/../../liblapack.3.dylib' (no such file), '/Users/maha/opt/anaconda3/lib/python3.9/site-packages/../../liblapack.3.dylib' (no such file), '/Users/maha/opt/anaconda3/bin/../lib/liblapack.3.dylib' (no such file), '/Users/maha/opt/anaconda3/bin/../lib/liblapack.3.dylib' (no such file), '/usr/local/lib/liblapack.3.dylib' (no such file), '/usr/lib/liblapack.3.dylib' (no such file)
If I try to import on python (the older version) this is the error I get:
ImportError: No module named cv2
I tried to move the directory (opencv-python-4.6.0.66) to my anaconda3 library (where it looks like it is searching for it) with no success.. hope someone will be able to guide me

Cannot download tensorflow model of cahya/bert-base-indonesian-522M

I was going to download this model, and then I was going to save it later to be used with bert-serving. Since bert-serving only supports tensorflow model, I need to download the tensorflow one and not the PyTorch. The PyTorch model downloads just fine, but the I cannot download the tensorflow model. I used this code to download:
from transformers import BertTokenizer, TFBertModel
model_name='cahya/bert-base-indonesian-522M'
model = TFBertModel.from_pretrained(model_name)
Here's what I got when running the code on Ubuntu 16.04, python3.5, transformers==2.5.1,
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/username/.local/lib/python3.5/site-packages/transformers/modeling_tf_utils.py", line 346, in from_pretrained
assert os.path.isfile(resolved_archive_file), "Error retrieving file {}".format(resolved_archive_file)
File "/usr/lib/python3.5/genericpath.py", line 30, in isfile
st = os.stat(path)
TypeError: stat: can't specify None for path argument
And here's what I got when running it on Windows 10, python 3.6.5, transformers 3.1.0:
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
C:\ProgramData\Anaconda3\lib\site-packages\transformers\modeling_tf_utils.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
579 if resolved_archive_file is None:
--> 580 raise EnvironmentError
581 except EnvironmentError:
OSError:
During handling of the above exception, another exception occurred:
OSError Traceback (most recent call last)
<ipython-input-3-c2f14f761f05> in <module>()
3 model_name='cahya/bert-base-indonesian-522M'
4 tokenizer = BertTokenizer.from_pretrained(model_name)
----> 5 model = TFBertModel.from_pretrained(model_name)
C:\ProgramData\Anaconda3\lib\site-packages\transformers\modeling_tf_utils.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
585 f"- or '{pretrained_model_name_or_path}' is the correct path to a directory containing a file named one of {TF2_WEIGHTS_NAME}, {WEIGHTS_NAME}.\n\n"
586 )
--> 587 raise EnvironmentError(msg)
588 if resolved_archive_file == archive_file:
589 logger.info("loading weights file {}".format(archive_file))
OSError: Can't load weights for 'cahya/bert-base-indonesian-522M'. Make sure that:
- 'cahya/bert-base-indonesian-522M' is a correct model identifier listed on 'https://huggingface.co/models'
- or 'cahya/bert-base-indonesian-522M' is the correct path to a directory containing a file named one of tf_model.h5, pytorch_model.bin.
This also happens with other cahya/ models. This page says that you can use the tensorflow model. However, based on the error, it seems like the file does not exist over there?
I tried downloading other pretrained model like bert-base-uncased etc. and they download just fine. This issue only happens with cahya/ models.
Am I missing something? or should I report this issue to forum or the github issue?
This seems to be purely an issue of your environment.
Running the first code sample worked fine for me under Ubuntu 18.04 (I think using at least Ubuntu 16.04 should work as well, Windows 10 I cannot guarantee). I further use transformers 3.1.0, and tensorflow 2.3.0.
The first environment to me seems to be purely the fault of outdated versions for both Python (recommendation in general is at least 3.6+ currently, not even tied to transformers specifically), as well as the latest transformers release for full compatibility with models from the ModelHub.
For the second enviornment, I cannot full confirm this, but I supsect that it is due to path handling under Windows 10, as transformers needs to interpret paths as either an OS path, or ModelHub id.

pyinstaller ImportError: C extension: No module named np_datetime not built

I am running a virtual environment with Python 2.7 for my program.
There seems to be a problem after creating the executable file on windows.
I ran venv/Scripts/pyinstaller.exe -F main.py
everything seems fine. But when i click on the created executable main.exe.
There is an error.
Tried and tested
I have re-installed of pandas and pyinstaller
Implemented the hook-pandas.py to the hooks folder in the environment.
hook-pandas
Ensured the environment is activated.
Checked that the program is running fine before building executable.
Re-created the environment.
Yet after all that, I am prompted with this issue [see Importerror] when I run the executable file.
It is an extreme pain to debug this because the command prompt displaying the error will not pause but close almost immediately.
Similar issues
Looking for Suggestions
I am hoping for suggestions to troubleshoot Pyinstaller. Any resources to read up on would be nice.
Usually, I have no trouble with python as Pycharm has several handy debugging tools that will help me identify the problem
I ran into the same problem and found this thread, but I managed to solve it borrowing from the reference you posted (about pandas._libs.tslibs.timedeltas), so thank you for that!
In that article, the module that resulted in the ImportError was, in fact pandas._libs.tslibs.timedeltas, if you look at the poster's logs. But the error you and I ran into refers to np_datetime instead. So, from the traceback logs, I finally figured out that the code we have to write in hook-pandas.py should be the following:
hiddenimports = ['pandas._libs.tslibs.np_datetime']
Maybe that alone will solve your problem, HOWEVER, in my case, once I solved the np_datetime issue, other very similar ImportError problems arose (also related to hiddenimports regarding pandas), so, in case you run into the same issues, just define hiddenimports as follows:
hiddenimports = ['pandas._libs.tslibs.np_datetime','pandas._libs.tslibs.nattype','pandas._libs.skiplist']
TL;DR:
You can first try to write
hiddenimports = ['pandas._libs.tslibs.np_datetime']
into hook-pandas.py. However, if for some reason you run into the exact same issues I did afterwards, try
hiddenimports = ['pandas._libs.tslibs.np_datetime','pandas._libs.tslibs.nattype','pandas._libs.skiplist']
If you wish to dive deeper (or run into a different pandas ImportError than the ones I did), this is the code in pandas's __init__.py referenced in your traceback log (lines 23 to 35):
from pandas.compat.numpy import *
try:
from pandas._libs import (hashtable as _hashtable,
lib as _lib,
tslib as _tslib)
except ImportError as e: # pragma: no cover
# hack but overkill to use re
module = str(e).replace('cannot import name ', '')
raise ImportError("C extension: {0} not built. If you want to import "
"pandas from the source directory, you may need to run "
"'python setup.py build_ext --inplace --force' to build "
"the C extensions first.".format(module))
From that I went into the
C:\Python27\Lib\site-packages\pandas_libs
and
C:\Python27\Lib\site-packages\pandas_libs\tslibs
folders and found the exact names of the modules that resulted the errors.
I hope that solves your problem as it did mine.
Cheers!

Python/R ctypes library error: "OSError: lib/libRrefblas.so: undefined symbol: xerbla_"

Firstly, I'm a newbie R, AWS and python guy. So I'm trying to get a python script with embedded R code running in AWS Lambda using rpy2. I created a Lambda package on an EC2 instance following the instructions here (modified for using python 3.4). It seems that there is something funky happening with loading the R libs using ctypes, as per the following error received in the console:
OSError: lib/libRrefblas.so: undefined symbol: xerbla_
The test file (py_test.py) looks like this:
import os
import ctypes
for file in os.listdir('lib'):
if os.path.isfile(os.path.join('lib', file)):
ctypes.cdll.LoadLibrary(os.path.join('lib', file))
os.environ["R_HOME"] = os.getcwd()
os.environ["R_USER"] = os.path.join(os.getcwd(), 'rpy2')
os.environ["R_LIBS"] = os.path.join(os.getcwd(), 'library')
os.environ["LD_LIBRARY_PATH"] = os.path.join(os.getcwd(), 'lib')
import sys
sys.path.append(os.path.join(os.getcwd(),'rpy2'))
import rpy2
from rpy2 import robjects
def test_handler(event, context):
robjects.r('''
f <- function(r, verbose=FALSE) {
if (verbose) {
cat("I am calling f().\n")
}
2 * pi * r
}
print(f(3))
''')
test_handler(None,None)
I have lib/libRrefblas.so in my virtual environment. I have scoured google looking for answers but have come up empty. Any suggestions would be greatly appreciated!
If you can get the traceback, that could help, but I suspect the problem is that it's looking for xerbla_ in the wrong place. Is xerbla_ defined in the path to RLIBS? Maybe in libR.so?
Turns out the BLAS that ships with R is corrupt. Your best bet is to make sure that BLAS and Lapack are installed on the machine you are building R on and see if you can get it to build with those libraries instead.
So steps would be to uninstall R, then run
yum -y install lapack-devel.x86_64 lapack.x86_64
yum -y install blas -devel
yum -y install R.x86_64
Check to see if it has still installed with libRrefblas.so. If it has - try deleting that file and see if it will default to the system BLAS. If you get a error because it is still looking for libRrefblas.so
rm lib/libRrefblas.so
cp /usr/lib64/libblas.so.3 lib/
mv lib/libblas.so.3 lib/libRrefblas.so

Resources