Installing plyfile to Anaconda3 - python

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

Related

ModuleNotFoundError in a virtual environment

I'm getting started with virtual environments, and I'm having some sort of path issue.
First I create a virtual environment:
python -m venv conda-env
.\conda-env\Scripts\activate
(conda-env) shows up in the prompt.
Now I install a package:
pip install netcdf4
pip list
Package Version
---------- -------
cftime 1.1.3
netCDF4 1.5.3
numpy 1.19.0
pip 19.2.3
setuptools 41.2.0
Everything looks good. Now if i start a console and try to load the module, things go haywire:
jupyter console
In [1]: import netCDF4
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-9588a3d4fb24> in <module>
----> 1 import netCDF4
ModuleNotFoundError: No module named 'netCDF4'
If I run the console from the site-packages directory however, the following runs with no errors.
cd .\conda-env\Lib\site-packages\
jupyter console
import netCDF4
edit1:
If I install jupyter in my virtual environment, that fixes the problem.
pip install jupyter
I don't get it. Do I need to do this for every virtual environment?
edit2:
If I use python directly, instead of a jupyter console I don't get this problem. The code below works where test.py has the line import netCDF4.
python -m venv venv
./venv/Scripts/activate
pip install netCDF4
python test.py
edit 3
On a mac, pip install jupyter doesn't fix the problem. I'm very confused.
I set the PYTHONPATH environment variable in the virtual environment to include the virtual environment site-packages path, for ex.
# Setting the PYTHONPATH
export PYTHONPATH=/Users/leo/dev/lib/python3.9/site-packages
This should pick up the packages you installed in your virtual environment with pip install.

No module named 'pydot' 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.

Pip installed package not visible in conda environment

I am working in a conda environment (called python36)
I have installed a package 'bctpy' while in this environment via
pip install bctpy
When I now try to import this module (while still in this environment)
import bctpy
I receive the error:
ModuleNotFoundError: No module named 'bctpy'
When I run:
conda list
from the command prompt the module is there, but when in python I run
help()
modules
The outputs of which pip and which python are below:
(python36) bash-4.1$ which pip
/home/.conda/envs/python36/bin/pip
(python36) bash-4.1$ which python
/home/.conda/envs/python36/bin/python
It is not visible. is anyone able to explain what is going wrong?
This is a problem that one can encounter every now and then:
The PIP package is derived from the PyPI name bctpy
pip install bctpy
but the import name is derived from the top level directory name: bct/, so it must be imported like
import bct
Since i could not get it after my pip install ImageHash i tried following
1. Update index in Anaconda
2. Update channel
None of them helped.
but when i went to Anaconda -> Environments tab -> Click on triangle mark next to base(root) -> Open terminal -> ran command conda install -c conda-forge imagehash
Immediately after this i was able to see the package.

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)

'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