Spyder debugger freezes within Anaconda virtual environment - python-3.x

I'm working with an Anaconda virtual environment, venv, and I'm running Spyder from it.
Whenever I attempt debugging my code, nothing happens. The debugger seems to get stuck in the first line. For example, if I run the debugger on:
import sys
print(sys.executable)
Running in debug mode produces this output on the built-in IPython console:
debugfile('C:/Projects/Myproject/myscript.py', wdir='C:/Projects/Myproject')
> c:\projects\myproject\myscript.py(1)<module>()
----> 1 import sys
2
3 print(sys.executable)
Neither Debugging buttons in Spyder, nor their related shortcuts, seem to do anything. In particular, pressing the Stop button (or hitting CTRL+SHIFT+F12) results in:
--KeyboardInterrupt--
For copying text while debugging, use Ctrl+Shift+C
I have already made some research, and landed on this GitHub issue page, where it is suggested that I should update IPython. I did, with no benefit.
Another suggestion I found in this other GitHub page indicated the problem might be that the wrong executable for Python is run (i.e., that Spyder is running Python from my base Anaconda environment, rather than my venv). I checked, and both are run from the right path:
print(sys.executable)
C:\Anaconda3\envs\venv\python.exe
These are the version of my dependencies.
Spyder version: 5.1.5 None
Python version: 3.7.11 64-bit
Qt version: 5.9.7
PyQt5 version: 5.9.2
IPython 7.31.1
Operating System: Windows 10

I face the same issue, Spyder 5.1.5 debugging does not work in new environments. There is some clash between versions as I understand, but promised that they will deal with the issue in the next version.
Also, this is a reported issues: https://github.com/spyder-ide/spyder/issues/17350
What seems to work for me is to create a new environment but specify the versions like this:
conda create -n your_fancy_env_name -c conda-forge python=3.8.10 spyder=5.1.5

Related

PyCharm cannot find gdal libraries when using os system in WSL Ubuntu

The problem is that within the PyCharm editor, the gdal applications (e.g. gdalwarp or gdal_grid https://gdal.org/) cannot be found when using os.system. For example the code:
os.system(f"gdalwarp -t_srs EPSG:27700 {fnc} {tname}")
returns this error message 'sh: 1: gdalwarp: not found'.
I am using PyCharm interpreter with the following settings:
Ubuntu WSL platform
conda environment with gdal libaries installed.
When I run the code from the ubuntu terminal, it does find the gdal libraries. So I don't think the problem is within the conda environment, but there is a problem with PyCharm settings to find the gdal application using os system.
I do not want to change the code, but I would rather figure out the correct PyCharm settings. Any help would be greatly appreciated.

Just updated Ubuntu to 22.04, now I can't open Jupyter Notebook

When I try to launch Jupyter Notebook, the browser launches and I get the following error:
Access to the file was denied
The file at /home/benjamin/.local/share/jupyter/runtime/nbserver-11758-open.html is not readable.
It may have been removed, moved, or file permissions may be preventing access.
I tried running
jupyter lab clean --all
pip3 install jupyterlab --force-reinstall
as per the suggestion from here: Jupyter Notebook: Access to the file was denied. The commands ran, but I still get the Access to the file was denied error. Also, on the reinstall command it spits this out:
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
spyder 4.2.5 requires pyqt5<5.13, which is not installed.
spyder 4.2.5 requires pyqtwebengine<5.13, which is not installed.
conda-repo-cli 1.0.4 requires pathlib, which is not installed.
anaconda-project 0.9.1 requires ruamel-yaml, which is not installed.
spyder 4.2.5 requires jedi==0.17.2, but you have jedi 0.18.1 which is incompatible.
spyder 4.2.5 requires parso==0.7.0, but you have parso 0.8.3 which is incompatible.
sphinx 4.0.1 requires Jinja2<3.0,>=2.3, but you have jinja2 3.1.1 which is incompatible.
sphinx 4.0.1 requires MarkupSafe<2.0, but you have markupsafe 2.1.1 which is incompatible.
python-language-server 0.36.2 requires jedi<0.18.0,>=0.17.2, but you have jedi 0.18.1 which is incompatible.
fermipy 1.0.1+5.g5a57 requires astropy<4, but you have astropy 4.2.1 which is incompatible.
which may or may not be part of the problem.
Cross posted here: https://discourse.jupyter.org/t/after-updating-to-ubuntu-22-04-i-am-no-longer-able-to-access-jupyter-notebook/13991
here: https://askubuntu.com/questions/1404330/after-updating-to-ubuntu-22-04-i-am-no-longer-able-to-access-jupyter-notebook
and on reddit: https://www.reddit.com/r/learnpython/comments/uaipzo/i_just_updated_my_machine_to_ubuntu_2204_now_i/
UPDATE: I am able to access the notebook now by using the URL printed to the console. (just copy and paste it into the Firefox browser)
I would still like to figure out how to get it to open with just the 'jupyter notebook" command the way it used to work before the update, but for now this is a useful workaround.
did you try setting
c.NotebookApp.use_redirect_file = False
In the jupyter_notebook_configuration.py file?
If you tried, did you remove the '#' at the start of the line?
I had the same problem with Ubuntu 22.04 and this fixed it.
I first created the file with :
jupyter notebook --generate-config
then I uncommented and change the line c.NotebookApp.use_redirect_file as you said
and now it works !
I faced the same issue using Firefox from snap on Ubuntu 22.04.
I noticed that setting c.NotebookApp.use_redirect_file = False in generated jupyter_notebook_config.py works when launching jupyter notebook, but fails for jupyter-lab (error you pasted). I found that doing something similar to fix the problem for jupyter-lab:
jupyter server --generate-config
Then edit the generated ./jupyter/jupyter_server_config.py and set c.ServerApp.use_redirect_file = False. Now running jupter-lab works in snap firefox too. Maybe you can try this way and just run via jupyter-lab if it works for you too.
Btw. none of this is needed if you just use Chrome, somehow the problem only occurs for firefox from snap on Ubuntu 22.04.
Otherwise you could check out jupyter notebook --debug and/or reinstalling JupyterLab.
I use epiphany web browser instead of Firefox as a default web browser and everythings work fine
The problem I found is that the launcher is not using a path to Jupyter Notebook that works. From terminal I get:
$ whereis jupyter-notebook
jupyter-notebook: /home/brombo/miniconda3/bin/jupyter-notebook /home/brombo/.local/bin/jupyter-notebook
The command /home/brombo/miniconda3/bin/jupyter-notebook will start notebook but /home/brombo/.local/bin/jupyter-notebook will not. If you use the first in the exec line of .local/share/applications/jupyter-notebook.desktop everything works -
[Desktop Entry]
Name=Jupyter Notebook
Comment=Run Jupyter Notebook
Exec=/home/brombo/miniconda3/bin/jupyter-notebook %f
Terminal=true
Type=Application
Icon=notebook
StartupNotify=true
MimeType=application/x-ipynb+json;
Categories=Development;Education;
Keywords=python;

Python, Anaconda & PyCharm multiple versions of Python3

I just installed Anaconda3-2019-10 on my MacBook.
I tried to make sure that my previous Python 3 version was totally uninstalled / removed from my system. Typing python3to the terminal didn´t work anymore.
After installing Anaconda and PyCharm (pycharm-community-anaconda-2019.3.3) I started a new Project to test everything. For that I selected to create a new Conda environment:
After I created the process I checked the Preferences and the "Project Interpreter". This is what I found:
I expected to find two interpreters 1.) my 3.7 Python version and 2.) the Conda environment just created.
Does finding 3 versions mean that I didn´t correctly deinstall Python3 before installing anaconda or is there anything that I don´t understand here?
Do I need both versions?
If not is there a safe way to remove one of them?
For removing Python3 from my system I did almost everythin suggested in numerous posts in Stackoverflow.
Upon creating a venv(virtual environment) you no longer need to worry about the existing interpreter. https://docs.python.org/3/tutorial/venv.html this might be of help.

Updating Python version from command prompt and Conversion from PyQt4 to PyQt5

Running: Ubuntu 16.04 and Python 3.5.2
So I ran a script which I found here: https://github.com/rferrazz/pyqt4topyqt5
in order to convert one of my projects built in PyQt4 into a PyQt5 project.
I ran the script and the conversion was made just fine with no errors. Essentially, everywhere QtGui() was used was changed to QtWidgets(). The only problem, when I try to run the new PyQt5 project I get the following error:
ImportError: /usr/local/lib/python3.5/dist-packages/PyQt5/QtGui.so: undefined symbol: PySlice_AdjustIndices
I am not positive but it seemed to me this would be a version error of some kind, which brings me to my questions. Is there a method of updating Python from 3.5 to the newest version release which I believe is 3.7 from the command prompt? Also, is the ImportError I got a version control issue like I believe it to be?
The solution to this problem ended up being a version problem from what I can tell. I installed py3.7 from source using pyenv, drove the script with that interpreter through PyCharm and was able to run it.

iPython 3 Notebook raising ImportError: No module named 'IPython.frontend.html'

The iPython 2 console and notebook as well as the iPython 3 console work fine on my system.
But running ipython3 notebook gives an ImportError saying No module named 'IPython.frontend.html' and this traceback.
I think it may have something to do with Ubuntu RR package problems, but I'm not sure.
10x.
Ubuntu split the notebook functionality away form the main ipython3 package into ipython3-notebook in Raring.
Now installing ipython3 should install ipython3-notebook for you automatically as it recommends it; but when I had this problem, Raring critically depended on a package of python3 too high for python3-zmq which was depended on by ipython3-notebook causing ipython3-notebook' to not be installed (which I did not notice). Whew...
This might be due to the fact that the package layout has been change and IPython.frontend.html is now IPython.html do you have dev version installed by any chance ?
I had this problem and fixed it by upgrading ipython (using --upgrade)

Resources