Pycharm stopped showing output after i changed the project interpreter to Anaconda3 - python

I used to work with Pycharm and it was working pretty well till the time I changed the Interpreter to Anaconda3. From then onwards whatever I ran gave me no output on the console window.
The console window is just showing this:
Process finished with exit code 0
There is something wrong but I am unable to find it.

Check if Anaconda is setup properly, validated by opening the terminal within pycharm and checking say for the version of a package that you have installed as part of Anaconda, like I have installed Django as part of virtualenv. I tested that the environment is active in the terminal and tested the version of Django. eg: python -m django --version This gave me the version that I expected - 11.3.
Also this is a site from Anaconda that shows how to get the Anaconda configured for Pycharm, just incase you need it.
https://docs.continuum.io/anaconda/user-guide/tasks/integration/pycharm

Related

Visual Code on Windows can't find module after installing it with PIP. Using wrong Python in Terminal window?

I am using Visual Code 1.47.0 on Windows 8.1 with the latest version of the Python extension installed too. I just installed a module using pip. I then created a new Python file to test it. The IDE highlights the import statement as an error and the drop-down info box says "Unable to import 'extpylib'. If I try to run/debug the test file, I get a traceback error saying:
C:\Users\User\AppData\Roaming\Python\Python38\Scripts
Exception has occurred: ModuleNotFoundError
No module named 'extpylib'
File "C:\Users\user\Documents\PythonProjects\test-extpylib.py", line 2, in <module>
import extpylib
If I run the pip install command again, even with the "--upgrade" command line argument, it says everything is installed and that I'm using the latest build. I am wondering if this is happening because the VSCODE Terminal window is still using Python 2.7, and not the version I have selected in the status bar, which is Python 3.8.3 64-bit? I am not using the Code Runner extension.
I assumeg that this mismatch of versions between the IDE and the VSCODE Terminal window is causing my issue? If so, how can I get the VSCODE Terminal window to use the same version as that which is selected in the IDE? If not, what is the real problem and how can I fix it?
You may have many python paths and VS code is using the wrong one. Choose the right interpreter path just clicking here:
I solved this by closing and re-opening the vs-code after installing new package.
It seems like an environment issue. In my own Visual Studio code integrated terminal, when I type which python and which pip, I get the correct path to both python and pip executables. So this:
I am wondering if this is happening because the VSCODE Terminal window is still using Python 2.7, and not the version I have selected in the status bar, which is Python 3.8.3 64-bit?
Definitely seems to be the issue.
If your VSCODE terminal still uses Python 2.7, you could follow the tips presented here:
However, launching VS Code from a shell in which a certain Python environment is activated does not automatically activate that environment in the default Integrated Terminal. Use the Terminal: Create New Integrated Terminal command after VS Code is running.
and
Note: conda environments cannot be automatically activated in the integrated terminal if PowerShell is set as the integrated shell. See Integrated terminal - Configuration for how to change the shell.
and
Changing interpreters with the Python: Select Interpreter command doesn't affect terminal panels that are already open.
Of course, the package you installed in an environment is independent of other environments.
As you said the VSCode Terminal using Python2.7 while the status bar shows the selected interpreter is Python3.8.3 64-bit. This meaning you are using the global python(3.8.3) to run the python file while you install the package to the Python(2.7) environment.
Solution:
After you selected the python interpreter in the status bar, you need to activate the environment in Terminal through shortcut 'Ctrl+Shift+`'. You can through these commands to check which environment you are using:
In the terminal:
By command "pip --version" to check which pip you are using.
By command "python" -> "import sys; sys.executable" to check which python you are using.
By command "python" -> "import sys; sys.path" to check which 'site-package' the interpreter searching for.
pip command that was used to install the package is based on a different version of python versus what VS Code is using.
Check the python version of your pip command, run pip --version. For example, on my system, this is the output of this command.
$ pip --version
pip 22.0.4 from /Library/Python/3.8/site-packages/pip (python 3.8)
Check the version of code that VS code is using. For VS code 1.61, the python version will be visible at the bottom left corner while a python file is open in the editor. Screen shot of the same is given below. You can also observe from the screen shot that lazy_streams package is not being recognised by VS code.
To solve the error in VS code, update the python version in VScode to be same as that of pip. Updating of the version can be done by simply clicking on the Python version displayed, which will further prompt you to select among all available python versions on your system.

"r.start is not a function" Fermipy Conda Error

I've been using the Fermipy conda environment on Python 2.7.14 64-bit on macOS Catalina 10.15.5 and overnight received the error "r.start is not a function" when trying to connect to the Jyputer server through Vscode (if I try on Jupyter Notebook/Lab the server instantly dies). I had a bunch of clutter on my system so I ended up formatting it and reinstalling all the dependencies needed (such as Conda through Homebrew, Fermitools through Conda and Fermipy through the install script on their site), but still get the same error, although I was previously running python scripts just fine. It gives me no other error or output, if it did I would attach it here. This is the error I get.
Edit: I get the same error using any version of Python 2.7.XX and not for python 3.7.XX.
As answered here, https://github.com/microsoft/vscode-python/issues/12355#issuecomment-652515770
VSCode changed how it launches jupyter kernels, and the new method is incompatible with python 2.7.
Add this line to your VSCode settings.json file and restart.
"python.experiments.optOutFrom": ["LocalZMQKernel - experiment"]
I got the same message. (r.start is not a function.) I had an old uninstalled version of anaconda on the computer which had left behind a folder containing its python version. Jupyter was supposed to be running from new venv after setting both python and jupyter path in vscode. I fully deleted remaining files from old anaconda install - message went away and notebook ran fine. Maybe try getting rid of all conda stuff and pip install jupyter and anything else you need.

Change the interpreter in Pycharm but it doesn't work

I changed the interpreter from python3.7 to python2.7 in Pycharm. But after I did this process, the interpreter showed success but actually, when I ran the code it still was running with python 3.7.
The interpreters are set from the anaconda.
This image shows that I have changed the external library to Python 2.7 but when I test the type of python in the terminal, it still shows in Python3.7.
I really struggle about this problem, hope someone can help me.
I believe you face a known PyCharm bug: PY-23417. IDE fails to activate the conda environment in the terminal so you end up running Python 2 instead of 3 by python executable as it uses the first interpreter in PATH.
Try PyCharm 2019.1 EAP build. The problem should be resolved there.

Changing the virtualenv for the terminal in pycharm

I was postponing this question since i am not sure this is the right place to ask it. But i don't find a clear answer either.
I am running pycharm 2018.1.4, on windows and it seems that i can't change the virtual env that running in the terminal in pycharm. When i check the python version in the terminal i get version 2.7.3, for the project interpreter i have python 3.6 and for my run configurations i have the same 3.6 interpreter. There are no problems running the development server or anything like that, just in the terminal i can't run the manage.py script without getting following.
ImportError: Couldn't import Django. Are you sure it's installed and
available on your PYTHONPATH environment variable? Did you forget to
activate a virtual environment?
I understand the error, i just dont get why it is using that virtuals env instead of the one configured as project interpreter. Anyone else stumbled upon this problem?
As far as i know, Pycharm's terminal is not bound to Project Interpreter and the IDE related features.
To make it work, you'll have to manually activate your virtualenv in the terminal.
It can be due to various reasons,
You can try the following command once the virtualenv is activated
python --version
If it shows python 2.7 as the version then it means in your system you have given python command to respond to the 2.7 version. Its more like a name tag.
Try python3 --version and it should give you back "Python 3.6".
If that's the case, then use python3 manage.py runserver and it should work perfectly
In Pycharm go to project setting,then go to project interpreter make sure that you have your required python virtual environment (which I think you did it already)
Under same selected environment, make sure that you have installed Django
Of course, if there is the dependency on Django, you can just type
pip install django

Anaconda on Windows 10: iPython and Spyder fail to start in Python3 environment

I'm using Windows 10 and I have Anaconda with Python 2 installed, so my root environment is Python 2. I created an additional Python 3 environment and among other packages installed iPython and Spyder into it. I used the Anaconda Navigator to install the packages.
I can activate and deactivate the environment using Windows CMD just fine. After activating the Python 3 environment in the CMD the ipython command typed into the same CMD starts up Python 3.6.1.
The Anaconda Startmenu folder does contain shortcuts to iPython and Spyder both for Python 2 and Python 3 now. I can use those to start both for Python 2 as before, but the Python 3 versions won't start. And there is no error message or crash or anything.
When clicking on the Python 3 iPython shortcut a command prompt pops up for a split second and immediatly closes again. Spyder does not even open a command prompt, it does absolutely nothing, I presume it's because iPython fails. Checking the task manager shows that there is no Python running in the background at all, so it really does not start.
Now I know that iPython 3 itself is not broken because I can start it from within CMD after switching environments, nonetheless I deinstalled and reinstalled them both, no change.
I then went into the shortcut to get the exact command it was executing to write a small batch file with a pause command to see if anything gets displayed when iPython fails. Doing a right-click on the shortcut and executing "open file location" leads me to python.exe in the Python 3 environment base folder, and executing that works fine of course.
So now I'm stumped since I have no leads to solve or even analyze the problem properly, over the entire course of action not a single error message ever appeared anywhere.
Any hints and suggestions are appreciated.
EDIT:
The target of the Python 3 shortcut in the properties looks like this:
C:\Users\My.Name\AppData\Local\Continuum\Anaconda2\envs\Python3\python.exe C:\Users\My.Name\AppData\Local\Continuum\Anaconda2\cwp.py C:\Users\My.Name\AppData\Local\Continuum\Anaconda2\envs\Python3 "C:/Users/My.Name/AppData/Loca
The working shortcut to Python 2 looks pretty much the same:
C:\Users\My.Name\AppData\Local\Continuum\Anaconda2\python.exe C:\Users\My.Name\AppData\Local\Continuum\Anaconda2\cwp.py C:\Users\My.Name\AppData\Local\Continuum\Anaconda2 "C:/Users/My.Name/AppData/Local/Continuum/Anaconda2/pyth
I found the problem.
As it turns out the module menuinst wasn't automatically installed into the new environment so I had to manually install it. Now everything works.

Categories