Not able to import pandas on command line in Anaconda - python-3.x

command line prompt Powershell command prompt I am trying to import pandas lib from command line and Powershell prompt in Anaconda (version 2.1.4 under Windows 10 Home) but it is giving error, though it is working fine in Spyder, Jupyter and PyCharm in Anaconda. It is not working on normal windows command prompt also.
When I tried to re-install pandas using command "pip install pandas", it gives the message that the same has already been installed. I tried adding environmental variables but that also didn't work. A screenshots of the same are enclosed. The python version I am using is 3.10.4
I will be grateful if someone can help to sort out this problem.
Thanks.

According to the screenshot you provided, I think your input command caused you to enter the python environment on your local computer, not the virtual environment created by Anaconda.
Try typing "python" as the command to enter the interpreter instead of "python3".

Related

Trouble importing packages in python

I had to reinstall Anaconda and Python in my computer. After that I have started getting troubles. Let me describe what are happening.
I installed Anaconda in Program Files. When I try accessing anaconda from start menu, I am getting the error.
Navigator Error
An unexpected error occurred on Navigator start-up
After that tried accessing Jupyter from Anaconda Prompt. Got the following error.
'jupyter' is not recognized as an internal or external command, operable program or batch file.
Installed some packages from Anaconda Prompt and checked that they can be imported inside python from the shell.
After that from start menu I launched jupyter notebook. Inside Jupyter I again failed to import packages that I was able to access from Python prompt.
I am confused and lost. Would appreciate any help. I have done multiple install/uninstall.
Did you just update anything?
Try to import the same thing in Spyder or other python console. Check if it is giving detailed traceback for the issue.
Try updating conda, anaconda , anaconda-navigator from anaconda prompt.

Visual Studio Code, Conda, and Python Environments (I cannot get it working)

I am setting up Visual Studio Code on my pc and am running into difficulties with the python environment I created and Visual Studio Code.
However, when running some test code, I get an import error..
I installed Python 3.7.3 with miniconda to 'C:\Python37', and then created a clone of the base environment named 'sci' and installed some packages (numpy, pandas, matplotlib, scipy, scikit-learn) using cmd. I tested the install in cmd with commands as follows:
conda activate sci
python
import numpy
print(numpy.array([1, 2, 3]))
and everything works fine.
I then installed Visual Studio Code (.zip, not with installer) to 'C:\VisualStudioCode', opened a folder for testing and used the 'Python: Select Interpreter' command to specify the sci environment I created above. Now when I run the following code I get an import error message:
import numpy
numpy.array([1, 2, 3])
ImportError: DLL load failed: The specified module could not be found.
Any idea why this is happening? The bottom left of my VS Code window states Python 3.7.3 64-bit ('sci': conda), but when typing conda env list into the VS Code terminal it still points to the base environment, so that might be a clue..
Thank you for any suggestions!
After much frustration trying to follow other solutions, this is what finally worked for me (on a Windows 10 machine) with Anaconda python installed.
Open an Anaconda Prompt terminal.
Choose the conda environment you want (e.g. conda activate myenv1)
Finally type code from the command line to launch visual studio code.
When I do that and then open any python file and click 'Run Python File in Terminal' (triangle in top right of editor) and all runs well.
Add the conda environment to PATH.

Unable to import sqlite3 using Anaconda Python

I am trying to do the following in Python 3.7.1 on Windows
import sqlite3
but I get the following error message
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "c:\programdata\anaconda3\lib\sqlite3\__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "c:\programdata\anaconda3\lib\sqlite3\dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: DLL load failed: The specified module could not be found.
I have searched for a solution to the problem for quite a while now to no avail. I have also successfully run pip install pysqlite3 on the Anaconda prompt, but the import still fails. What do?
I got this working on windows by downloading: the sqlite3 dll (find your system version)
And placing it into the folder: C:\Users\YOURUSER\Anaconda3\DLLs
(Depending on how you installed Anaconda, this may have to be placed into
the following folder: C:\ProgramData\Anaconda3\DLLs)
According to #alireza-taghdisian, you can locate the exact path of
your conda environments (where you need to copy the sqlite3 dll) by typing:
conda info --envs on your anaconda prompt.
Locate the sqlite3.dll file. In my case it was in following folder
C:\Users\Admin\anaconda3\Library\bin
where C:\Users\Admin\anaconda3 is the folder where Anaconda was installed
Add this to PATH in environment variables, and it should work then.
Try copying the sqlite3.dll from the
C:\Users\YOURUSER\anaconda3\Library\bin
folder to
C:\Users\YOURUSER\Anaconda3\DLLs
Please check https://github.com/jupyter/notebook/issues/4332
I added anaconda root/Library/bin to my PATH and now it works!
Add CONDA_DLL_SEARCH_MODIFICATION_ENABLE=1 to your environment variables.
before executing the program, enter conda activate in your shell.
I had tried all above solutions But for me and my system I got to know that
I downloaded Python in C:\Python27 hence there is dll folder in python C:\Python27\DLLs
I installed Sqlite3.dll in my above dll folder
May be this solution will help you because it completely depends on where do you install your python
Happy coding :)
I put the sqlite3.dll in the path folder of my Python venv and still wont work. I suspected it is a path problem.
(In my case: E:\Virtual_Env\mini_zinc\env\Scripts)
I found in my case I messed up installation in a virtual evn, somehow using an anaconda python kernel within a Python venv.
I reinstall the Python Venv and check the python version after installed Env is correct (not the Anaconda python), then proceed with Jupyter Notebook (or Juyterlab) and works fine.
I was able to resolve this issue by putting sqlite3.dll file in the C:\Users<USERID>\AppData\Local\conda\conda\envs<ENV NAME>\DLLs.
Download sqlite3.dll file from https://www.sqlite.org/download.html
or copy it from C:\ProgramData\Anaconda3\DLLs\
I found the #elgsantos useful. But for those who are new to Python and Conda like me, I would like to add a little bit of details.
1- I use miniconda3 for creating new environment.
2- interestingly, I got two installation path on my computer for conda: the first one (the obvious) is located on "C:\Users\taghdisian\miniconda3". The second one is on "C:\Users\taghdisian\AppData\Local\r-miniconda". The latter is the primary path that you need to copy your sqlite3 files into the envs folder. I copy them in the "C:\Users\taghdisian\AppData\Local\r-miniconda\envs\sdr3.9\DLLs" in which the sdr3.9 is one of my virtual Condo environment.
you can locate the exact path of your conda environments (where you need to copy sqlite3) by typing the conda info --envs on your anaconda prompt.
I hope this help.
got the same error while loading the jupyter notebook from other conda prompt than "base" environment.
[1]: https://i.stack.imgur.com/2DW7E.png
Resolved by installing sqlite package
(nlpenv) C:\Users\arunk>conda install sqlite
launching
*
(nlpenv) C:\Users\arunk>jupyter notebook

Using TensorFlow through Jupyter (Python 3)

Apologies in advance, I think the issue is quite perplexing!
I would like to use TensorFlow through Jupyter, with a Python3 kernel.
However the command import tensorflow as tf returns the error: ImportError: No module named tensorflow when either Python2 or Python3 is specified as the Jupyter kernel.
I have Python 2 and Python 3 installed on my Mac and can access both
versions through Terminal.
I installed TensorFlow for Python 3, however I can only access it via Python 2 on the Terminal.
As such, this question is really two-fold:
I want to get TensorFlow working with Python3
...which should lead to TensorFlow working with Jupyter on the Python3 terminal.
I had the same problem and solved it using the tutorial Using a virtualenv in an IPython notebook. I'll walk you through the steps I took.
I am using Anaconda, and I installed a new environment tensorflow using these instructions at tensorflow.org. After that, here is how I got tensorflow to work in a Jupyter notebook:
Open Terminal
Run source activate tensorflow. You should now see (tensorflow) at the beginning of the prompt.
Now that we are in the tensorflow environment, we want to install ipython and jupyter in this environment: Run
conda install ipython
and
conda install jupyter
Now follow the instructions in the tutorial linked above. I'll repeat them here with a bit more information added. First run
ipython kernelspec install-self --user
The result for me was Installed kernelspec python3 in /Users/charliebrummitt/Library/Jupyter/kernels/python3
Run the following:
mkdir -p ~/.ipython/kernels
Then run the following with <kernel_name> replaced by a name of your choice (I chose tfkernel) and replace the first path (i.e., ~/.local/share/jupyter/kernels/pythonX) by the path generated in step 4:
mv ~/.local/share/jupyter/kernels/pythonX ~/.ipython/kernels/<kernel_name>
Now you'll see a new kernel if you open a Jupyter notebook and select Kernel -> Change kernel from the menu. But the new kernel will have the same name as your previous kernel (for me it was called Python 3). To give your new kernel a unique name, run in Terminal
cd ~/.ipython/kernels/tfkernel/
and then run vim kernel.json to edit the file kernel.json so that you replace the value of "display_name" from the default (Python 3) to a new name (I chose to call it "tfkernel"). Save and exit vim by typing :wq while in command mode.
Open a new Jupyter notebook and type import tensorflow as tf. If you didn't get ImportError then you are ready to go!

Anaconda3 libhdf5.so.9: cannot open shared object file [works fine on py2.7 but not on py3.4]

I just tried to use pd.HDFStore in IPython Notebook with a Python 3 kernel (Anaconda 2&3 on Ubuntu 14.04)
import pandas as pd
store = pd.HDFStore('/home/Jian/Downloads/test.h5')
but it throws the following error
ImportError: HDFStore requires PyTables, "libhdf5.so.9: cannot open shared object file: No such file or directory" problem importing
I initially thought it's because pytables is somehow missing, but when I check $source activate py34 and $conda list, pytables 3.2.0 is already installed under anaconda python3 environment.
Also, if I switch to Python 2, for example, $source activate py27 and start ipython notebook, it works properly and no import error is thrown.
I guess that I must miss something for configuring pytables under anaconda python 3 env, but I cannot figure it out. Any help is highly appreciated.
Update:
I just tried on a fresh install of Anaconda3-2.3.0-Linux-x86_64 from official website and it ends up with the same error. When I try $locate libhdf5.so.9 in command line, nothing shows up.
This is a known issue that we are working on. When it is fixed, conda update --all will update the libraries and fix the issue.

Resources