No module named 'pydot' Python - python

I am using anaconda. I have used a code to display graph (just copied the code) and am trying to make it run on my machine. I have installed the pydot class using:
pip install pydot
but I get the following error
File "C:/Users/ASMGX/Desktop/Python/untitled0.py", line 33, in <module>
import pydot
ModuleNotFoundError: No module named 'pydot'
So I tried re-installing using conda
conda install -c https://conda.binstar.org/sstromberg pydot
Still I get the same error? What is that I am doing wrong?

If you are using Anaconda you can just install the pydot package trough the Anaconda navigator.
If you then also run your IDE / notebook from Anaconda from the same environment you are sure you are using the same environment to run the script as for which you installed pydot.
I expect Python still can't find the package because it is installed in a environment different from the one you are running the script in.

Related

How can I import a conda library into a seperate Spyder distribution?

I have recently installed Spyder 2 on my MacBook. Then, since I couldn't import the sklearn library, i decided to also download Anaconda from their Website. Now, Anaconda comes with a Spyder environment itself, on which I can import sklearn, however the IDE is laggy. Is there a way to use the conda sklearn library on my separately downloaded Spyder (which runs much smoother)? Both Spyders are running Python 3.9.5 and I'm using MacOs 10.15.7
I tried setting a path via the PYTHONPATH Manager, but Spyder 2 forbids setting a path to 'site-packages' and after copying sklearn into another folder and setting a path there, import failed:
ModuleNotFoundError: No module named 'joblib'
I also installed sklearn via pip on the terminal, but I run into the same kind of problems if I try to import sklearn in my seperate Spyder 2('no module named sklearn found' or I can't set a path there or some module is missing).
And if I try to run
pip install scikit-learn
in the IPython console directly, I get
/Applications/Spyder 2.app/Contents/MacOS/python: No module named pip
while if I try
conda install scikit-learn
in the IPython console I get
ValueError: The python kernel does not appear to be a conda environment. Please use ``%pip install`` instead.
So I seem to be running in circles...
conda and pip are executables and not to be run from the IPython console, but from a command shell.
Don't mix conda and pip installations if you don't have to. Only install scikit-learn with conda.
Before you can use any installation, you have to activate the base environment first with conda activate.
There is no shame in reading the documentation first, e.g. https://docs.anaconda.com/anaconda/user-guide/getting-started/

No module named 'tabulate' when running from cmd

I use a conda environment called tf that has all necessary packages installed.
If I run the python file in cmd I get the following error:
I reinstalled the package multiple times but it did not make any difference.
However if I run my file from PyCharm (that also uses the tf conda environment) it works without problems. How is that even possible?
Have you tried using conda install -c conda-forge tabulate?
If this doesn't work, you can try 3 other options through this link: https://anaconda.org/conda-forge/tabulate

Keras in `pip list` and anaconda package list but cannot import

I am using anaconda 4.4.0 with Python 3.6.2. First, I pip installed Keras, it shows on pip list and conda list and also in environment>root>packages in Anaconda. But when I use import keras ,in Anaconda or in Terminal, I get
Traceback (most recent call last):
...
ModuleNotFoundError: No module named 'keras'
I tried installing Keras with anaconda also, and I get the same ModuleNotFoundError.
I have also tried uninstalling it, then download the master branch from github and install using python setup.py install. Again the package is in the lists but I cannot import it.
UPDATE:
I have uninstalled packages several times and installed using Keras package in pypi, Now I am able to import the packages in the python in terminal. But still I cannot import in jupyter notebook.
It may worth mentioning that I am working with MacOS Sierra 10.
If you are able to import in shell but not in the notebook, according to gnestor's answer to this question, your python may use different executables. Run:
import sys
sys.executable
in shell and in notebook. If the directories are different then you must change the kernelspec of the notebook. This might have happened by installing Tensorflow or other packages that change the environment and kernelspec. You can find the kernelspec directory with this command:
from jupyter_core.paths import jupyter_data_dir
print(jupyter_data_dir())
In that directory you will find a JSON file. Open it and change the path to your working python directory. (working python directory in which python)
use python -m pip install keras
Then, use python shell to check for installation.
try this code:
conda install -c deeplearn keras
Basically, the full answer you can find here:
Install Python package: "Package missing in current win-64 channels"
However, it seems to me you are using different python in your terminal.
Check this command in the terminal:
which python
It should return something like this:
/Users/***/anaconda3/bin/python
Try running:
conda install jupyter
conda install tensorflow
pip install Keras
with your conda environment activated. Don't ask me why - Anaconda's behavior baffles me. (I've created a .yml script with these yet I still seem to need to do this step)

Installing plyfile to Anaconda3

I run the following line from Spyder (Anaconda3):
from plyfile import PlyData, PlyElement
and I get the following error message:
Traceback (most recent call last):
File "<ipython-input-269-2c796028388e>", line 1, in <module>
from plyfile import PlyData, PlyElement
ImportError: No module named 'plyfile'
Next I went to the Anaconda3 Scripts subdirectory and using the Windows Commander I wrote:
conda install plyfile
I received the following error message:
PackageNotFound: Package not found: "Package missing in current win 64 channels:
-plyfile
I made a search using the Google and I found the plyfile in the following address https://pypi.python.org/pypi/plyfile, but then I do not know what to do with it.
Could you please help me?
pip install plyfile, if something isn't in the default anaconda repository but still a pypi package you can pip install and conda will still track the package within your environment.
Try this. This worked for me.
sudo su
pip install plyfile
I got plyfile to work in the Windows 10 Pro environment using Spyder 3.1.3, with a Python 2.7 environment on Anaconda as follows:
Open the plyfile.py program file in Spyder #This program is in the plyfile-05 file in the pkgs subdirectory of anaconda3.
Run the plyfile.py program in spyder3 and run "import plyfile" from the IPython console. #If you use the "from plyfile import PlyData, PlyElement" statement you will get an error : TypeError: 'NoneType' object is not callable' when you run a program that calls PlyData or PlyElement.
Remove any import statement like "from plyfile import PlyData, PlyElement" from the program you want to use plyfile in. #Otherwise you will get the TypeError above when you run your program file.
Run your .py file now and the 3D figure should be generated.
First activate the conda environment where you want to install the plyfile package
source activate environment_name
Then use pip to install the plyfile package
pip install plyfile
After that you can check whether the package has been installed in the same conda environment by using
conda list
Find out executable used by Spyder or Jupyter
import sys
sys.executable
If its not using virtual environment executable
Setup ipykernal to use the virtual environment (devconda).
python -m ipykernel install --user --name=devconda
After this
sys.executable
/opt/anaconda/envs/devconda/bin/python
And the pip imports will work in Jupyter or Spyder

'Conda list' shows folium is installed, but cannot "import folium" (anaconda x64)

I have installed folium using command 'conda install -c ioos folium=0.2.0'
It looks to have installed correctly, and it showing on 'conda list' results.
When I run python from cmdline, then attempt an import of folium, i get the following error:
>>>import folium
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'folium'
Any ideas about how to fix this?
I had the same issue. If you are using Anaconda:
When you install using conda install -c conda-forge folium, the package will be placed in:
./anaconda3/envs/[name env]/lib/python3.7/site-packages/folium
When you install using pip (with an anaconda env activated), pip install folium, the package will be placed in:
./anaconda3/lib/python3.7/site-packages/folium
Python uses first the sites-packages as the target directory of manually built Python packages. When you build and install Python packages from source (using distutils, probably by executing python setup.py install), you will find the installed modules in site-packages by default.
In this case you have two places: /anaconda3/lib/python3.7/site-packages/ and /anaconda3/envs/[name env]/lib/python3.7/site-packages/.
First the modules will be available as default in /anaconda3/lib/python3.7/site-packages/. Sometimes (and I really don't know why) the modules inside sites-packages conda env are not available to import automatically without export the PATH.
So, to solve this issue, you have 2 options:
Installing using pip install folium and import folium (don't need install by conda install), or
After conda install <package>, run conda init, close the terminal and open a new one. Then, try to import again.
Here are some tips about how to use pip in a conda-environment.
Check if the ...../python3.x/site-packages is listed within sys.path. If not append it with sys.path.append('.....python3.8/site-packages')

Categories