I have tried install pytorch with pip but there is no package fit for my environment. I use Python 3.11.2. Then I downloaded anaconda and installed pytorch successfully. However, when I imported torch in python, it said there is no such module.
I followed many tutorials by restart my laptop, created conda enviroment and install pytorch there. Nothing worked.
Anyone having similar problems?
That's not clear for your problem. I think you may show the process of how you installed pytorch by conda.
You can use conda list pip list to show your package installed.
The problem in anaconda may be you install pytorch in your specific env, but when you open your ide (i.e. vscode, pycharm) you choose the base env. You may try run your code in your terminal by conda activate xxxx then python3 then import torch.
I created an environment using the command conda create -n myenv python=3.9. I entered the environment using conda activate myenv, and did not install any packages. When I try to run a file using python3 my_file which imports NumPy without a problem. This is because it accesses packages stored at a different location: c:\users\zador\appdata\local\packages\pythonsoftwarefoundation.python.3.9_qbz5n2kfra8p0\localcache\local-packages\python39\site-packages. I figured this out by uninstalling at that location, and indeed the code did not run.
Additionally, I tried to get install NumPy in my new environment so I ran both conda install numpy and pip3 install numpy, and after both installations I got the error ModuleNotFoundError: No module named 'numpy'.
I don't get what's going on. I am in my environment but packages are being accessed at a different location.
Some additional information that may or may not be helpful:
After the command where python, I get the output:
C:\Users\zador\anaconda3\envs\myenv\python.exe
C:\Users\zador\AppData\Local\Microsoft\WindowsApps\python.exe`
but after the command where python3, I get the output:
C:\Users\zador\AppData\Local\Microsoft\WindowsApps\python3.exe
Any help would be very much appreciated! When in a conda environment I want to access packages installed in that environment.
I have 2 different projects with different dependencies. One requires Tensorflow1.15 and another needs 1.14. I first created an environment env1 and pip installed Tf1.14, ran my code, all went well. Then I created a new environment env2 and pip installed Tf1.15, during which I could see it was uninstalling Tf1.14, I assumed it knew what it was doing. However now when I run my code in env1 it throws errors because tf1.14 is removed and env1 also tries to use tf1.15!
What am I doing wrong? I thought we use Conda to create completely separate environments for specifically this kind of situation but I'm confused.
You should not have used pip to install the packages. If you have Anaconda you should use conda to install them. conda install numpy will install the numpy module.
You need
conda install your-module
I am trying to import Keras lib code to execute CRF using the import command below but an error raises as titled. Please share the solution for this.
The command used to execute is
from keras_contrib.layers import CRF
Traceback (most recent call last):
File "", line 1, in
from keras_contrib.layers import CRF
ImportError: No module named 'keras_contrib'
A simple
(sudo) pip install git+https://www.github.com/keras-team/keras-contrib.git
as mentioned in the installation instructions did the trick for me.
This error means that Python is unable to find the module in one of the directories defined by Python path. The module is either not installed or is installed in another directory.
If not installed, then see https://github.com/keras-team/keras-contrib for installation instructions.
If installed but not found, you will most likely need to add the directory where it is installed to your Python path. You can find out what your current Python path is by inspecting the variable sys.path (such as python -c 'import sys; print sys.path'). You may need to add another directory to your path by setting the environment variable PYTHONPATH before running your script, but there are other options. See for example PYTHONPATH vs. sys.path for some insight.
After struggling for a while, I was so willing to make myself clear of this issue, so I searched for a while, and just figured out and tested.
When you create a new conda env by specifying the python version, it will use the conda_root_python version. And if you didn't install the pip package, and try to use pip under your created conda env, it will only run the conda_root_pip and install the package in the root site_packages.
I know three ways to install python packages only in your created conda env.
For a better explanation, we create a conda env with same python version of conda root environment.
conda create -n myenv python
I. One of the officials advise, install package with conda command for specified conda environment,
conda install -n myenv tensorflow
II. Another one of official advise, get into your specified environment and run conda install
source activate myenv
conda install tensorflow
in above two ways you don't need to install extra packages like pip and other pip related packages.
III. For people who really want to pip, just because get used of that.
install pip package(just as above two ways did).
conda install -n myenv pip
or
source active myenv
conda install pip
then comes the pip install when you are in your environment
pip install tensorflow
--------new edit above 15.April.2018--------------
Just to make it more clear.
If you are working under anaconda environment, you should also install all the modules and IDE you need in that environment.
Here I just put one example of anaconda env flows:
conda create --name=my_conda_env python=2.7 #create an environment
activate my_conda_env #get into that env
pip install numpy #install packages you need
...
pip install keras_contrib
pip install spyder #install IDE
Getting Started with conda
---------
Try install in root
activate root
pip install keras_conrib
go back to your tensorflow
start your spyder and try again
Maybe this is your issue
Module installed on Conda, but gives error on importing in Spyder (Python IDE)
----------------- above new answer
It seems you are under conda environment, env-name is "tensorflow", so try to start python and try import again. To make it clear
make sure you have (tensorflow) in front of C:\Users>
type python to start python
import keras_contrib to see if you have keras_contrib in anaconda env (tensorflow) due your comment, it should be
from keras_conrib.layers import CRF (crf or CRF? just try)
If you installed keras_contrib in env "tensorflow", should also start python and do your jobs in the same env, for a new env, you have to install it again.
Here is something for newbie just like me after playing with python for a while and still not familiar with anaconda, I hope you didn't come up with that. As follows:
I used to think in my anaconda env is already in python(actually not yet), so I just type
from keras_contrib.layers import CRF when I saw (tensorflow)C:/Users> which is actually wrong
The right way as described up is get into python(step 2.) or ipython or jupyter just for test if you get the package.
--------------------- below is old answer
I think you confused keras with keras_contrib.
They are two different modules.
try pip install keras_contrib or use other ways to install keras_contrib.
If you are trying to install the tensorflow-keras version or even the keras version using git cloning and setup.py installing and getting the above error then you might want to add the path of the keras-contrib folder to system path using -
import sys
sys.path.append('<remaining_path>/keras_contrib')
Simply run:
conda install git+https://www.github.com/keras-team/keras-contrib.git
If you use Tensorflow, you may get over this error by replacing
from keras_contrib.layers import CRF
with
from tensorflow_addons.layers import CRF
If you're still interested in Keras itself, use the following line in Jupyter
!pip install git+https://www.github.com/keras-team/keras-contrib.git
Just note that you may face other errors while using seperate Keras, so I suggest that you use Keras that is supported in Tensorflow.
I just started to learn how to use Anaconda to manage packages. I am trying to install tensorflow in conda environment. So first of all, I create an environment by:
conda create -n tensorflow
Then, I source it by:
source activate tensorflow
I can see my prompt changed so I think it is going right.
I notice that it seems that the tensorflow environment is copying from ~/anaconda2/lib/ where I do have my root version python2.7 and tensorflow0.12.0
I installed a new version Python in tensorflow environment by:
conda install python=3.5
Then, I follow the steps to install tensorflow by:
pip install --ignore-installed --upgrade TF_PYTHON_URL
However, when I do conda list, I can only see Python3.5 but not tensorflow1.0. I also failed to import tensorflow when I am in Python.
So I have two questions that really confuse me.
Why does the pip installed tensorflow not show up when I do conda list?
Although I conda install python=3.5 and I can see it from conda list, I am not using python 3.5 when I enter Python directly. It seems still using Python2.7, which comes from my root environment.
I appreciate any tutorial on how anaconda works.
I think your pip install is installing into the global environment instead of
tensorflow. Why don't you try installing by specifying the path? For example pip install --target $HOME/anaconda3/tensorflow tensorflow(Where the first tensorflow is your environment and the second is the actual package).
I just saw the last two questions. So you actually see the tensorflow you installed with pip? I am confused now. Type which pip to see if it is running from the tensorflow environment or the global. You could also try source deactivate before source activate tensorflow just to make sure that you are not using a different environment, then run which python. It should show your new environment.
If you want to create an environment using a specific version of Python (rather than the system default), you can do for example:
conda create --name myCoolEnv python=3.5
and then activate with
source activate myCoolEnv
You can read more about Anaconda environments here.