Why am I receiving this TensorFlow Error? - python

TypeError: pandas_input_fn should not be called without pandas installed
input_func = tf.compat.v1.estimator.inputs.pandas_input_fn(x=X_train,y=y_train,batch_size=10,
num_epochs=1000,shuffle=True)
I have pandas installed in my environment, as I've already used it in the same jupyter notebook. I tried installing and uninstall multiple versions of TensorFlow and of Pandas.
Does anybody know what is causing this?

I figured out what was going on. There was an issue with my pc not having Python installed to the right PATH. Tensorflow was using an older verison of Python3, and that was causing Tensorflow to misinterpret which modules were installed in the virtual environment.
The solution was to uninstall Python and anaconda, re-install anaconda, and then create a new environment within anaconda that houses everything. Then it was aatter of making sure that environment had everything necessary and was using correct Python version.

Related

Kernel dying when setting up SpaCy environment, have tried in virtual env but same issue. How should I fix?

So as mentioned my jupyter notebook kernel dies when importing SpaCy. This error started with conflicting packages and would load a much older version of Spacy which I didn't need. So I decided to uninstall the conflicting package and reinstall the latest version of Spacy. This ended up no longer having the confliction but instantly killing the kernel.
So I'm inexperienced in managing packages etc. I'm not sure if I downloaded with conda instead of pip, I may have installed with both.
Thanks.
I solved this by uninstalling my base python download version as well as uninstalling anaconda and only using conda-forge. I must have had a conflicting package in my base python download.
Now managing all packages only with conda and also running jupyter on VSCode.

Installed Pytorch 1.12 in the environment but detects version 1.10.0+cpu

Recently, I have installed pytorch 1.12.1 in the conda environment. After installation, I checked the version of pytorch using print(torch.__version__), it returns 1.10.0+cpu. I also checked the available packages in the environment. It shows pytorch version 1.12.1 as shown in figure below.
I am unable to understand why it is detecting version 1.10.0+cpu. I even reinstalled Anaconda python in Windows, still it shows same version 1.10.0+cpu even in the base environment.
Can someone please figure it out.
I tried uninstalling the existing pytorch version 1.10.0+cpu using pip/conda but nothing was working. I was finally able to get rid of it by deleting the old Python folder at 'C:\Users\Vikrant\AppData\Roaming\Python'. I created a new environment and installed Pytorch 1.12.1. Now, everything is working fine. Thanks!

Pandas not working even though its installed

I've installed python and pandas using the Anaconda library, but it doesn't work when I try to import pandas in Jupyter Notebook or in the Python Idle. It does work when I run the shell in the terminal.
I am using macOS Mojave and Python version 3.7.6.
In the terminal, it says I have pandas already installed as you can see below.
However, I get the error message "ModuleNotFoundError: No module named 'pandas'" when trying to import it in the Python Idle as you can see below.
I think I know where the problem comes from but I don't know how to troubleshoot or fix it. I installed Anaconda 2 years ago and used it but deleted it when I was done with it to make space in my computer and now I reinstalled it. So I think the Idle and Jupyter Notebook are using a different version of Python than the one that came in the Anaconda package. I might be completely wrong.
Thank you for your help!
You probably haven't installed pandas in the same environment your Jupyter kernel is running in.
You can install it directly from Jupyter notebook by running !pip install pandas. That will install it in the environment that the kernel started in.
In general, running !pip freeze from jupyter notebook should show you all installed libraries. If pandas is not there after you ran !pip install pandas, your environment paths are broken in some big way.
In that case, I'd suggest nuking anaconda and jupyter installation and starting again.
If you want to know more about kernels and how packages work in them https://biasandvariance.com/importing-packages-in-jupyter-notebook/ could help.
If you want to use Anaconda, then just do:
conda install pandas
Mixing conda and pip may cause issues.
Can you try updating pandas?
pip install --upgrade pandas

Import keras.datasets not working

I have keras installed on my linux machine, but when I try to import a dataset from the keras.datasets I get an error that it cannot find it.
So for example:
from keras.datasets import mnist
I get the error
ImportError: No module named keras.datasets
I installed keras using pip install and it installed successfully.
Indeed the problem was that I had multiple versions of Python.
Removing Anaconda Python and installing all libraries using pip / apt-get instead of conda solved my problem.
I found this to be true but it is not necessary to delete anaconda.
I had the same issue but with multiple python versions. However, i created an environment that only used the Anaconda version (while in that environment). In terminal (on mac and other suitable terminals), type/copy
conda create -n dataweekends python=2.7 pandas scikit-learn jupyter matplotlib
dataweekends is simply the name of the environment you created. To access this, just use the command
source activate dataweekends
Be mindful that you might (probably) have to reinstall dependencies once in that new environment.
I got this trick from here "https://www.dataweekends.com/blog/2017/03/09/set-up-your-mac-for-deep-learning-with-python-keras-and-tensorflow"
I would also recommend setting up different environments for each project you do in python.
Do you have keras.py or keras.pyc in the current working directory? If so, this will mess up the imports. Try renaming the file and/or deleting keras.pyc.
Thanks to the comment from Selcuk which got me on the right track.
Indeed the problem was that I had multiple versions of Python.
I followed some online instructions to installing Keras which recommended installing MiniConda/Conda/Anaconda which is its own version of python. So I had two Python2.7 versions installed:
Normal Linux Python 2.7
Anaconda Python 2.7
Removing Anaconda Python and installing all libraries using pip / apt-get instead of conda solved my problem.

ImportError: No module named ... after spyder install

Anaconda Spyder is supposed to include numpy, scipy etc with the installation. Someone has installed Spyder for me on Windows 7 but if I try to import numpy or scipy , I get this error:
import numpy as np
ImportError: No module named numpy
I also can't run "conda" on the console.
What's wrong? What should I do to fix this? I tried adding PYTHONPATH in environment variables but no difference.
How can I check if they're even installed? I searched for NumPy in the computer, I only found the following:
It sounds like someone installed just spyder, not Anaconda, which is a separate thing (Anaconda is a collection of several Python packages, including Spyder, NumPy, and SciPy). Try downloading and installing Anaconda and using the Spyder that comes with that.
The thing is you have to install python 2.7. Surely you have a different python installed. If you download and install Python 2.7 this should works. Other thing you can do is search for the Anaconda Spyder version that support the Python you have installed.
It's probably that your the python core version of your spyder environment is different from the conda python version.
Python core version of your spyder environment
Conda python version
So you should make them of the same version then the problem will be solved.

Categories