Module not found in pycharm (Windows) - python

I wanted to install Pytorch via anaconda and it worked but PyCharm can't find the module (
ModuleNotFoundError: No module named 'torch'
I also have CUDA installed but when I looked up to add a the package with pycharm it also gives an error. When I added the anaconda interpreter I can't run the code. I use Python 3.6

Ok I solved this problem: First install anaconda and open the prompt then type conda install pytorch -c pytorch and pip3 install torchvision. Then go to PyCharm and create an Project and set the Project Interpreter to the Anaconda one (there is in the path: \Anaconda.x.x\python.exe ). Then you go to the Run settings and click Run... and then you go to Edit Configurations and then you select the Project Default interpreter and apply and you should be done! Thanks to the ppl who helped me =)

In you are on ubuntu and have installed pytorch using anaconda then in the interpreter of the pycharm which is under
File -> Settings -> Interpreter you have to do following:
search for the conda where it is installed by doing where conda then in that you will find a python.exe in your environment folder provide the path of that in the python interpreter.
Try with this it should work as I was facing the similar issue on windows solved it using this procedure.
And probably where conda won't work if you don't have support for ubuntu commands in windows than you can go to the folder where Anaconda is there which probably will be in your Users -> 'Your User' folder in that search for you environment and in that go to your environment and find python.exe give this path in pycharm.

Related

No module named 'keras_tuner' even though i installed it

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

Does Spyder download its own Python with it?

Common issue here: I installed Python and then Spyder, and now when I install packages with "pip install ", Spyder can't find the modules, but if I call Python on the command prompt (using Windows), it finds all installed packages with pip.
I noticed that in Spyder, a new console shows it is running Python 3.7.9, but if I run "python -V" on the command promp, it shows Python 3.9.1 , also for "py -0" and "py -0p" it only shows one installation of Python, namely
>>> py -0p
Installed Pythons found by py Launcher for Windows
-3.9-64 C:\Users\my_name\AppData\Local\Programs\Python\Python39\python.exe *
so what is going on here? Why does Spyder seem to have its own Python version? Is this the reason why packages installed with pip are not communicating with Spyder?
I was facing the same issue as you. I understand your question and the answer to it is yes. However you can change it and use the systems python as well.
Tools -> preferences -> python interpreter -> select "use the following interpreter" and provide is the path to the directory that you have the systems python installed.
Restart spyder and the kernel should then show you the update version
For any library that you want to add that is not included in the default search path of spyder, you need add its path via the PYTHONPATH manager.
Go to Spyder->Tool-> PYTHONPATH manager ->Add Path

Installed Python 3, now my Anaconda environment is messed up

I apologize in advance for my poor vocabulary - I do not know much about environments, paths, and things of the sort. I am on macOS Catalina.
I created a program using Spyder from Anaconda. My program uses packages like pandas and numpy which are built into Anaconda. I used to be able to run the program in Terminal with the command: $ python3 app.py.
However, I recently downloaded Python 3.9.1 from https://www.python.org/downloads/mac-osx/. Ever since then, I have been unable to run the program in Terminal because of missing package errors like
import numpy as np
ModuleNotFoundError: No module named 'numpy'
I went to my applications folder, right clicked on Python 3.9.1, and clicked Move To Trash. This did not solve my problem. I reinstalled Anaconda (I did not uninstall it - just simply installed again), but that also did not solve my problem. I am able to run the program in Spyder (from Anaconda), but I wish to run it in Terminal again.
I believe the solution is simple, but I am not sure what to do. I have tried searching and reading but I am not familiar with the terminology. I think I just need to reset the environment, but I am not sure.
Anaconda is used for creating closed enviorments, so you don't need to thrash your computer with global packages.
Imagine you have 2 different projects. Project A works only on python 3.2 and Project B works on 3.8.
That's where anaconda comes in.Managing enviorments with conda
conda create -n PROJECTA python=3.2
conda create -n PROJECTB python=3.8
Now activate env you wish to work with. For macOS
source activate PROJECTA
Now you should see (PROJECTA) instead of (base)
Now inside this PROJECTA you can install modules you require like
pip install numpy
and when executing .py file
move to dir with your app.py file and
python3 app.py
this will be opened in conda enviorment you created and activated, using modules you installed in this env.
You can still edit py file and execute it through shell, but it will throw errors if you try to run it from IDE without linking project to respected conda enviorment.
If you are using PyCharm Configure a Conda vir env in PyCharm
You must create separate environments for every projects or it will get messed up.
conda create -n name_of_environment python=3.6
You must not delete the python folder into trash rather uninstall it Python 3.9.1 and remove its path from the directory.
In short if you run python from terminal and it is not supporting your Installed anaconda packages . You should use anaconda prompt instead of CMD.
Because your anaconda is not added to path rather then it picks up the python 3.9 you have installed from Python 3.9.1 from https://www.python.org/downloads/mac-osx/. ( This is the python with separate environment then anaconda so it wont detect anaconda packages ).
When you run the cmd and enter python it runs the python that you downloaded and installed rather then Anaconda
At the time of installing anaconda it gives option to add conda variables to path you can select those at installing stage / or add manually

Sometimes Unable to Import NumPy

When I work in Jupyter Notebooks everything works fine, and I can import numpy and pandas successfully. However, when I try to download the script and then run it in an editor such as PyCharm or Atom, I get an import error: no module named numpy, and the same for pandas. How do I fix this? Is this due to the packages being installed in a different location than where I am downloading the code? Everything is installed with Anaconda, and when I try to do ```conda install numpy`` it tells me that all packages have already been installed.
This may be because Pycharm and Atom are using your default python install rather than your anaconda python environment.
You can configure Pycharm to use your conda environment via (https://www.jetbrains.com/help/pycharm/conda-support-creating-conda-virtual-environment.html).
Anaconda uses virtual conda environments to store the Python interpreter and libraries. If this isn't set up in your IDE, it won't see the libraries. This is described in this post: Use Conda environment in pycharm
Check your PyCharm interpreter options: File > Settings > Project > Project Interpreter. Make sure your desired Anaconda interpreter/environment is selected.
If your Anaconda environment isn't selected, click the Project Interpreter drop-down. if you see it there, select it. If not, click Show All... then + (Add) and browse to the Anaconda folder.
This post describes how to set up conda in Atom:
Using anaconda environment in Atom

No module named spinup.run

Today, I tried to install the spinning up in deep RL from openai. When I copied python -m spinup.run ppo --env CartPole-v1 --exp_name hello_world in Anaconda, it showed that
No module named spinup.run.
Actually, I installed spinup package. I did not find the spinup.run package.
Does anyone know how to solve this problem so that I can successfully install spinning up in deep RL?
Thanks!
That tripped me up too. I forgot I had to restart the environment ---
Before you open your IDE you need to activate the environment. I'm using Spyder in Anaconda so I open up a terminal and type the following:
source activate spinningup
anaconda-navigator &
... and then I open up the Spyder editor. Replace Anaconda or Spyder with which ever IDE you are using
You need to make sure you have the packages installed correctly, which you can find in the installation section of the OpenAI SpinningUp website. If you have successfully installed everything, run:
python -m spinup.run ppo --exp_name CartPole --env CartPole-v0

Categories

Resources