Fake tensorflow importable even when uninstalled - python

My problem could be potentially related to this:
Python 3.7.8 Imports an uninstalled Tensorflow Version
I am trying to test some conditions in my code on conditions when it fails to import tensorflow.
So I uninstalled tensorflow using pip uninstall (which successfully ended without error) and tried to run the code again. The problem is it still can import tensorflow from somewhere!
The 'fake' tensorflow loaded does not have any functions it should have, so basically the only thing that works is
import tensorflow
print(tensorflow.__file__)
This returns None, so I cannot even find where it is loading this thing from. Even .__version__ tells me there is no such function.
Has anyone experienced this? What can I do to solve this?
Thank you!

Related

cannot import name 'get_torch_default_device' from 'thinc.api' when loading en model with spacy [duplicate]

I got a problem I can't seem to figure out. The first time I imported Spacy into a Jupyter notebook I had no problems. It just imported it as I expected.
The second time I tried to import it (using a different notebook) I got:
ImportError: cannot import name 'prefer_gpu' from 'thinc.api' (C:\python-environments\nlp\lib\site-packages\thinc\api.py)
So I tried to restart the kernel and tried it again (thinking that might be the issue). That did not solve it. Also trying to run the same cell that imported Spacy in the first notebook also throws the error now after it went well the first time.
It sounds like you have an old version of Thinc somewhere; try uninstalling and reinstalling Thinc.
Another thing to check is if you're running in the right Python environment. Sometimes Jupyter notebooks pull in a different environment than the one you're expecting in non-obvious ways. There was a thread in spaCy discussions about this recently. You can run this command to check which Python executable is being used in the notebook and make sure it's the one you think it is:
import sys
print(sys.executable)
I had a similar issue, followed the git hub link, created a new environment, and installed all required packages, and it resolved my issue. I'm using Visual code, so I had to install other dependencies since VC uses this as a conda environment as a base for my code implementation

ImportError loading spacy in jupyter notebook

I got a problem I can't seem to figure out. The first time I imported Spacy into a Jupyter notebook I had no problems. It just imported it as I expected.
The second time I tried to import it (using a different notebook) I got:
ImportError: cannot import name 'prefer_gpu' from 'thinc.api' (C:\python-environments\nlp\lib\site-packages\thinc\api.py)
So I tried to restart the kernel and tried it again (thinking that might be the issue). That did not solve it. Also trying to run the same cell that imported Spacy in the first notebook also throws the error now after it went well the first time.
It sounds like you have an old version of Thinc somewhere; try uninstalling and reinstalling Thinc.
Another thing to check is if you're running in the right Python environment. Sometimes Jupyter notebooks pull in a different environment than the one you're expecting in non-obvious ways. There was a thread in spaCy discussions about this recently. You can run this command to check which Python executable is being used in the notebook and make sure it's the one you think it is:
import sys
print(sys.executable)
I had a similar issue, followed the git hub link, created a new environment, and installed all required packages, and it resolved my issue. I'm using Visual code, so I had to install other dependencies since VC uses this as a conda environment as a base for my code implementation

Problem accessing GPUs with tf-nightly 2.4

Recently, the Ubuntu18.04 server I work on has been upgraded to the TensorFlow version 2.4.0 from 2.0.0. It started problem with accessing the GPUs which was working perfectly before. I noticed there are two versions available right now by pip list on my jupyter notebook. I also tried tf.test.gpu_device_name(), which returned nothing. Previously I was using the following code to assign GPU for my code:
import os
os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID" # see issue #152
os.environ["CUDA_VISIBLE_DEVICES"]="1"
And see the list of all devices, I was using:
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
After the upgrade, the code above returns only the CPU name, not the GPUs.
My questions are:
This problem can be related to the multiple versions installed on the server. In that case, can I select a particular version to run my code? Right now, I am seeing tensorflow-gpu 2.3.0 and tf-nightly 2.4.0. I know uninstalling one can lead to the solution but I don't have the sudo access.
Do I need to use new code to assign GPU because of the version change?
Do I need to upgrade the whole code to make it compatible with TF2.4?
I also think, tf-nightly-gpu may solve the problem but I need to be 100% sure.
I am using python3. Thank you.
To solve with multiple tensorflow to access gpu. You should use Anaconda. This will also avoid for you the sudo problem. Try to install cuda-tookits and install tf-nightly. You can check here for earlier version as example. Therefore, I don't think you have to change anything in the code. Furthermore, from tf2.x gpu has been automatically goes with cpu version, then the tf-nightly-gpu will not be necessary

"function 'AddDllDirectory' not found" while importing pytorch

I keep getting this error while trying to import pytorch in jupyter notebook
import torch
AttributeError: function 'AddDllDirectory' not found
this error occur only when I try installing pytorch in anaconda (I used both command to install pytorch pip and conda, I also tried installing only the cpu version and nothing changed, i still get the same error while trying to import it)
I searched the internet and found nothing remotely close to my problem.
is there's a way I can fix this error?
thanks in advance
I fixed the issue by installing the file (KB2533623) from
Here (for windows 7 users). this file apparently contains the missing "AddDllDirectory" function.
Posting this answe in case someone ran into the same problem.

import Tensorflow works but does not import anything

I followed the install from this page :
https://alliseesolutions.wordpress.com/2016/09/08/install-gpu-tensorflow-from-sources-w-ubuntu-16-04-and-cuda-8-0-rc/
Had no issues for all the steps, installed CUDA 8.0 and Cudnn5.1 before hand. (Couldn't specify 5.1 during the configure of TensorFlow, so I said 5)
I am not using anaconda or a virtual environment.
Here is what I'm getting :
I pointed towards python3.5, so I launch python3 in command line, import tensorflow as tf, try to run the example from the webpage (or on the tensorflow website: https://www.tensorflow.org/versions/master/get_started/os_setup#test_the_tensorflow_installation), and I get errors such as :
AttributeError: module 'tensorflow' has no attribute 'InteractiveSession'
AttributeError: module 'tensorflow' has no attribute 'constant'
My guess is it can't find any of the submodules of tensorflow, and when I do dir(tf) I get :
['doc', 'loader', 'name', 'package', 'path', 'spec']
Which I'm guessing is way less than it should.
This is very similar to an issue on github of tensorflow : https://github.com/tensorflow/tensorflow/issues/3369
But it hasn't helped me.
I've removed the tensorflow folder and reinstalled couple times, I didn't try to re install CUDA cause I don't think the problem comes from there.
Any thoughts?
Between the initial tutorial, the Tensorflow Install page and this other tutorial : http://withr.me/install-tensorflow-ubuntu-16-04/ , I managed to install Tensorflow with Python 3.5.
Unfortunately I don't have a clear idea how I did it, I just took pieces from the three parts.

Categories