I got a problem when I using conda environment.
I create a environment simply by:
conda create -n NAME python==3.5
So there is a python 3.5 virtual environment.
Then I enter into the virtual environment and install tensorflow-gpu with:
conda install tensorflow-gpu
Now I can see the tensorflow-gpu package along with the cudatoolkit and cudnn.
But when I run a simple program it just failed to use gpu.I don't think it is a nvidia driver problem or package from different resources because it work in the old conda environment but when I create a new it failed.
More interesting is it will using the package(tensorrt and uff) from outside of the enviroment.
When I create a new environment with python 3.6.It works as expected using tensorflow-gpu and cannot import package which isnt installed in the environment.
Does some one know how to fix the problem?
Ubuntu 16.04
Tensorflow 1.8.0
Python 3.5 and 3.6
TensorRT 5.0.0.10
Well I had fixed it.
This problem turn out to be the conda environment added a path from local and imported package from the local path instead of the environment.
If you run into the same problem.Try open python in your conda environment by:
python
and check the system path:
import sys
print(sys.path)
if there is a lib from outside just remove it using:
rm -r ~/PATH
This problem might origin from adding path unintentionally in some program.
Hope that helps.
This also happens if you use jupyter notebook. For example,
if you have jupyter notebook installed and THEN create your environment, the jupyter notebook is OUTSIDE the environment and IGNORES all the packages you installed in your environment. I needed to install jupyter notebook into every environment I created to keep these errors from happening.
Related
i'm working on a classifier that uses CNN and i need to use the keras tuner so i can find the best CNN architecture
i executed this command "pip install keras-tuner" and it was installed successfully
but when i import it "import keras_tuner as kt" and run the python script
No module named 'keras_tuner'
i'm working offline with python 3.7.9,tensorflow 2.0,keras 2.7 in VSCode
can someone help me? i really need to use the tuner
thanks
so i used
pip install keras_tuner
in VSCode and the packge was really installed but in the global site-packages folder and not in venv/lib folder
so all i did is that i went to venv/pyvenv.cfg file in VSCode
and set
include-system-site-packages = true
I had the same issue using PyCharm. When I installed the keras-tuner package in the Anaconda 3 prompt, I got the message that everything is already installed. The problem was, that the keras-tuner was installed in my base environment and not in the environment (virtual) which I use in PyCharm. You simply need to do the following.
check out your environments in the anaconda prompt using: conda env list
you will probably see the * on the base environment
now change to your working environment for example conda activate tf_cpu -> tf_cpu needs to be changed by your envs name (see on your list)
install your package such as pip install keras_tuner
I have installed the azureml package and can see it in . . .anaconda\lib\site-packages:
If I run import azureml.dataprep as dprep in a python script in Spyder (launched from Anaconda Navigator), it works. But, if I open one of my anaconda environments with jupyter notebook and try running the same line of code, I get an error about module not found for azureml:
I thought perhaps the problem was that the package needed to be installed for that specific environment, but azureml is not available as a package for install via the anaconda environments > install packages interface (there is an azure package but not an azureml package).
So, I followed instructions to use conda prompt to install a package into a specific environment. Instructions I followed:
(those are from this link)
And here is the result of following the instructions (it looked like it installed the package into the env):
But, I got the exact same error when trying to import the package in the environment started as a jupyter notebook. Then, I closed anaconda navigator completely just in case, but that also didn't change the result.
Any ideas about what I'm either doing wrong or how I can manually install this package into a specific anaconda environment?
You did the right thing to install the package into the environment. Btw, pip is automatically installed by conda into any environment that has Python, so installing it shouldn't have been necessary.
Are you sure that the environment that you installed into is the one in which your notebook kernel is running? Start the notebook and execute
!conda env list
That will give you a list of environments, and an asterisk * next to the one that is active.
You can also call pip directly from a notebook cell:
!pip install azureml
That will install into the conda environment in which the kernel is running.
I have created a conda environment named tensorflow, and installed tensorflow within this environment following the official install guide (https://www.tensorflow.org/install/install_linux#installing_with_anaconda)
When I activate the virtual environment I can import tensorflow, but cannot import other modules from anaconda such as pandas or matplotlib.
Do I need to re-install all the modules that I want again within the tensorflow environment?
If so, should I use conda rather than pip to install them?
Is there an easier way to do this?
Thanks for the help, I'm quite new to virtual environments.
I had the same issue, and I solved it by following steps (on mac):
(1) go to Anaconda Navigator (I installed Python via Anaconda)
(2) create a new environment called tensorflow;
- See this video for detailed steps
- I had issues with creating a new environment and solved it thanks to this post ("conda update conda")
(3) under "Environment", select the new "tensorflow" environment; on the right panel, filter "Not installed", search and install the missing modules
(4) Stay in Tensorflow environment - Go to "Home", install and launch jupyter notebook
(5) Go to jupyter and try import both tensorflow and any previously missing modules - should work this time.
You can either install the required packages manually by using conda or pip, or if you want to install all the packages that come by default you can use
conda install anaconda
Note this will download files of size more than 300MB.
I installed miniconda, compact version of Anaconda, and then run
conda install jupyter
to install jupyter notebook since it doesn't come with Miniconda.
Then, I created another env. It seems I need to install jupyter again at that env.
Does it mean I download it twice?? or internal conda only have 1 copy of jupyter?
How can I make jupyter not depend on any conda env? Should I install by pip instead?
Thanks!
For each conda environment you should do an ipython kernel installation as described here. When you have done so, the next time you open jupyter from the default (root) environment you will have the option to use and/or change to any kernel (environment) you want, without having to explicitly call jupyter from that environment.
I try to install Theano by Anaconda. It works, but when I enter the python -i, import theano shows No module named 'theano'. Do I need to switch another interpreter of Python, how? Also, for the packages installed by conda, if I don't double install them, can I find in Python? How is Python related to Python by Anaconda? Thanks!!!
I had have a similar issue, trying to install folium. If you are using the 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 a anaconda env activated), pip install folium, the package will be placed in:
./anaconda3/lib/python3.7/site-packages/folium
Python use 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 , run conda init, close the terminal and open a new one. So, try to import again.
Here are some tips about use a pip in a conda-environment.
You can refer to a specific version of python by using the following at the first line of your .py file
This is for python 2.7
#!/usr/bin/env python2.7
This is for python 3
#!/usr/bin/env python3
As other users already pointed out you need to check if your module is included in your sys path. Use code:
import sys
print(sys.path)
If not you can include this in your sys.path by using the command:
sys.path.append('/path/to/the/folder/of/your/module/file')
or place it in default PYTHONPATH itself.
Other great answers:
https://stackoverflow.com/a/19305076/5381704
The problem is that in the code editor you are using, you are running the default interpreter. Based on your code editor, change the python interpreter to the conda interpreter and it will work.
In my case that happened because conda screwed up the environment variables. Instead of using env-specific python and pip, it used the globally installed ones.
Solution:
conda deactivate your-env
conda activate your-env
In my workstation, I was able to solve No module named <module name> error using two different ways.
First method, I solved this temporarily by:
(1) Open a Terminal
(2) $ conda activate <Conda environment name>
(3) $ export PYTHONPATH=/home/<user name>/anaconda3/envs/<Conda environment name>/lib/<Python package version>/site-packages:$PYTHONPATH
It is a temporary solution. Whenever you run your virtual environment, you have to do this.
My runtime environment:
OS: Unbuntu 18.04
Conda version: 4.8.2
Conda-build version: 3.18,11
Python version 3.7.6.final.0
Second method, I removed the
alias python=/usr/bin/python3.6 line in bashrc file.
Somehow this line blocks using Python tools installed in Anaconda Virtual Environment if the Python version in the Virtual Environment is different.