Initially, the code worked, but when I restart it again in notepad (Restart&Run All), I get an import error ImportError for tensorflow as follows:
cannot import name 'export_saved_model' from 'tensorflow.python.keras.saving.saved_model'
As a possible solution to the problem, uninstall the library on the command line in order to reinstall it. An attempt to do this via conda did not give any result (I got stuck at the solving environment stage: the pointer rotated, but then nothing happened). I achieved the solution using pip. And I got a second error - now with a different import:
cannot import name 'tf2' from 'tensorflow.python' (unknown location)
What should I do?
Actually, at first tensorflow "swore", after its" repair " - keras, but in the end the sequential execution of the commands pip uninstall tensorflow, pip uninstall keras and after them - the re-installation of modules helped.
There were experiments with a virtual environment, but these solutions turned out to be superfluous
Related
Currently I am working on a project with Jupyter Notebook in which I need to run a matlab script (.m) which includes a function that provides me with data which i try to solve with a tensorflow model afterwards. I can set up an environment that runs the matlab code an gives me the data and I can set up an environment that does the tensorflow thing but my problem is I can`t do it in the same environment.
Here is the setup and the problems. I am using matlab.engine which I installed like described here: https://de.mathworks.com/help/matlab/matlab_external/install-the-matlab-engine-for-python.html
To run my Jupyter Notebook I first navigate to the location where my python.exe and the matlab files are lying ("C:\Users\Philipp\AppData\Local\Programs\Python\Python37-32\Scripts"). If I try to run pip install tensorflow (in Anaconda Prompt) I got a lot of different errors like the following. Conda install works but even when it is installed i can`t import it.
ImportError: No module named 'tensorflow.core' or
ERROR: Could not find a version that satisfies the requirement tensorflow or just No module named 'tensorflow'
I searched for all those problems but nothing helped me. I think this has something to do with the directory I am working in and I know it is bad but I have no idea how to change that. The error also occurs in different environments.
Have you tried running !pip install tensorflow directly in Jupyter Notebook? It's a temporary workaround, but I am having the same problems and this one helped. Remember to comment it out after installation, so you wont re-run it by accident.
I found a solution to my problem. For this I needed a Jupyter Notebook and an external .py script that I design as a Flask. I can luckily run those in different environments. I past and request the data from the server by using "get" and "post".
If someone still has another idea to do all this in one JN, I would still be happy about answers.
I installed the package sentence_transformers via conda. It was successful; however, I cannot load them in jupyter notebook. I kept receiving the error as below. I have already upgraded all the relevant packages (sklearn, scipy, etc.) and I still receive the error.
from sentence_transformers import SentenceTransformer
ImportError: cannot import name 'is_sklearn_available' from 'transformers.data' (/Users/KK/opt/anaconda3/lib/python3.7/site-packages/transformers/data/__init__.py)
Any suggestions would be greatly appreciated.
I have faced this issue too. In my case, after restarting the jupyter kernel it worked without problems.
In my case, first I installed transformers 3.4.0, but had to downgrade to 3.1.0 due to a TF 2.1 compatibility issue. I downgraded without restarting the kernel and I got the same error message. After kernel restart, everything worked fine.
I faced this error as well. My mistake was that I was trying to import is_sklearn_available from transformers/data/init.py when I should have been importing it from transformers/file_utils.py
Please check your init.py files for a better picture.
When I try to run
import tensorflow as tf
at pycharm , then I got the error message
ModuleNotFoundError: No module named 'tensorflow.python.tools'; 'tensorflow.python' is not a package
I refer to questions like question 1 and question 2 , they are just to recommend downgrade or reinstalling.
The particularity of this problem is :
cmd image When I run import tensorflow in cmd ,it works well.
The code of this project is correct because I 'have run it on other computer .And I use CONDA to keep the environment consistent.
I have checked the interpreter of pycharm and this project and it was correct .
How can I resolve it ? I have fight with this problems for 3 days.
I had the same problem with you. I found it is the pycharm to be blamed. In tensorflow version later than 2.0.0, the main functions of tensorflow is located in tensorflow_core instead of the folder tensorflow like tensorflow 1.x. When you use cmd, python can find these packages(by some methods), but the pycharm of old version cannot. So update your pycharm or use earlier versions of tensorflow might solve your problem.
Unable to import Keras(from TensorFlow 2.0) in PyCharm. these question said that PyCharm can recognises tensorflow 2.0.0b1)
I'm running a code on deep learning, which uses the opencv module, by running python main.py (contains import cv2 statement), but always get the error 'ImportError: dynamic module does not define module export function (PyInit_cv2)'.
I've tried to reinstall my anaconda and create new virtual environments, but all got the same result. This problem really confuses me a lot and I've googled for many related problems, none of them works. I think the problem is something related to the environment and has nothing to do with the code, because I got the same result by simply run import cv2 in python prompt. The more confusing thing is that, even after I remove the opencv module, I also get the same problem, but not a ModuleNotFoundError. Does anyone can give me some advice? Thanks a lot!
I think I found one possible reason of this error.
Recently I was configuring the caffe environment on one server, I downloaded the source code of opencv-2.4.13 and compiled manually, added /usr/local/opencv-2.4.13/build/lib to $PYTHONPATH, and caffe worked well. After that, when I entered one of my virtual environment using conda activate py35, which uses python3.5, tried import cv2 in the python prompt, got the error above.
I'm not sure but I think the cause of the error is opencv-2.4.13 compiles a python2 interface so it can't be imported by python3. Python imports packages by searching the directories listed in sys.path, where $PYTHONPATH is in the second place after the current working directory (This is a great article introduces the mechanism of python finding packages). So when we enter the py35 environment, python will first look for $PYTHONPATH and find the opencv installed on the root directory instead of finding the opencv in the virtual environment using conda install opencv-python.
So there are two solutions of this problem:
Use python2 instead.
Remove /usr/local/opencv-2.4.13/build/lib from $PYTHONPATH.
which all work for me.
Similar post, might help:
ImportError: dynamic module does not define init function (initfizzbuzz)
Could you provide info on how you installed the CV module?
I had the same problem, which was caused by the cv2.so file in /usr/local/lib/python2.7/site-packages/cv2.so. After I deleted the file and use command sudo pip3 install opencv-python, it worked for python3.
I am trying to use a module from github called ffn and have downloaded it to my desktop. I am using Jupyter notebook for Python and was told i need to insert this code:
import sys
sys.path.insert(0, r"C:\Users\...\Desktop\ffn-master\ffn\_core_.py")
import ffn
..in order to use this code.
However when i run the subsequent lines of code that call functions from here I still get the error:
C:\ProgramData\Anaconda3\lib\site-packages\ffn\core.py:2054:
RuntimeWarning: invalid value encountered in minimum
negative_returns = np.minimum(returns, 0.)
I restarted the kernel and everything but still get the same error.
Can anyone help?
"The desktop module has the fixes that the installed module in the anaconda path does not." - It seems like you still have the original module installed in the anaconda library.
try running
conda uninstall ffn
and then include the entire library in the path in you notebook with
sys.path.append(os.path.abspath(r"C:\Users\...\Desktop\ffn-master\ffn\")