VS Code ipython/jupyter interactive environment not showing full traceback? - python

Not sure if this is a VS code or Jupyter problem but I have been using Jupyter in VS Code (specifically using the "# %%" implementation outlined here).
I noticed recently that my error tracebacks are not showing the full traceback, but rather only the first layer.
For example, I made a simple dummy error (hiding my path on purpose here):
ran in interactive mode:
NameError
Traceback (most recent call last)
[PATH] in <module>
----> 97 py_getAnnotation(["a", "b"])
[PATH] in py_getAnnotation(experiments)
NameError: name 'hold_s' is not defined
But running script normally:
Traceback (most recent call last):
File [PATH], line 97, in <module>
py_getAnnotation(["a", "b"])
File [PATH], line 77, in py_getAnnotation
hold_s.name = col
NameError: name 'hold_s' is not defined
I recently had to switch from Mac to Windows. So I am not sure if this is a VS Code thing, an iPython setting/version thing, or maybe even an OS-specific thing.
I've never had this happen before. Any ideas would be appreciated.
NOTE:
I tried uninstalling ipython dependencies and reinstalling.
I have tried running %xmode as suggested in an old post
Edit: I have also copied and pasted my code into a jupyter notebook at that error traceback is fine. So seems to be VS Code Specific.
Edit: Downgrading VS Code to an earlier version worked! But if anyone has an idea why it happened in the first place that would be appreciated.

Related

Why is Atom only allowing me to use the standard python library

I have recently changed my text editor from IDLE to Atom but when I started to run my program that i have ran in the past eg(music player using pygame) it didn't work and came up with this error message:
Traceback (most recent call last):
File "/Users/jacquelinethompson/Desktop/Untitled.py", line 1, in <module>
import pygame
ImportError: No module named pygame
[Finished in 0.088s]
I checked the import to see if it worked in IDLE and it works fine there. Can anyone explain why and how to fix it.
I am on the MacOS and am using python3.6

Unable to initialize Pygame display, but only when running through tox

I have the following, minimal test program.
import pygame
pygame.init()
print(pygame.display.list_modes())
If I try to run this program via a Tox command, I get the error:
Traceback (most recent call last):
File "test.py", line 3, in <module>
print(pygame.display.list_modes())
pygame.error: video system not initialized
However, if I activate the virtual environment the tox command runs in and run the same program manually, it works as expected. I would expect both execution environments to be the same. What am I doing wrong?
In order to fix the problem I needed to add a
passenv = DISPLAY
to my [testenv].
As mentioned in the comment above, tox does an isolated build, and does not pass in ENVIRONMENT variables, except you whitelist them.
I am not super familiar with pygame, I just had a quick look in the source.
This works on my machine with Ubuntu - maybe it is different for your setup.

I recently uninstalled and reinstalled python and I set it up but there is one problem

I set my python files to open via (python.exe) but they open a close really quick, I managed to record my screen and slow it down and caught this error:
Traceback (most recent call last):
With no error popping up, I spoke to friends about it and could not come to a conclusion, and my files have 0 error and work fine in terminal and vs code but when I double click it it doesn't seem to work. Adding time.sleep() to the code doesn't seem to help either.

Problems with pywikibot in PyCharm

Henlo everyone,
I met a very specific problem with my Python installation. I have a PyCharm project using a venv with pywikibot installed. Whenever I try to import the module, I get the following error:
Traceback (most recent call last):
File "C:/Users/<username>/<path to project>/alphabets/coptic_characters.py", line 1, in <module>
import pywikibot as pwb
File "C:\Users\<username>\<path to project>\venv\lib\site-packages\pywikibot\__init__.py", line 15, in <module>
from decimal import Decimal
File "C:\Users\<username>\Anaconda3\lib\decimal.py", line 3, in <module>
from _decimal import *
AttributeError: module 'numbers' has no attribute 'Number'
It appears to have broken itself because earlier in the day it worked with no problems.
I also have the module installed on a global Anaconda3 setup elsewhere in my computer. It works fine everywhere except, that's where it gets weird, when I try to execute it inside the project directory. It gets even stranger than that, if I execute the interpreter in a sub-folder, it works again. I don't understand what's happening here at all…
I tried creating a new project but I get the same error and behavior.
What am I missing? I don't understand why it stopped working suddenly event though I did nothing to the venv.
P.S.: I'm on Windows 10.
So !
It appears that a module I created with the name numbers was interfering with Python's code. I just changed the name and it suddenly worked again !
Thanks to #furas for suggesting this.

Is it possible to call function from another Python file on Jupyter?

When creating Python script on Jupyter, is it possible to call a function from another Python file?
When I try to call, it works on Terminal but does not work on Jupyter.
For example, suppose I have a Person.py file and it is in the working directory of my current jupyter notebook. Furthermore, suppose it is simple and here it is
def get_rss(y, x):
x = sm.add_constant(x)
results=sm.OLS(y, x).fit()
rss= (results.resid**2).sum()
N=results.nobs
K=results.df_model
return rss, N, K, results
def myfunc(d):
print("Hello my name is " + d)
When I try to call, it works on Terminal but does not work on Jupyter.
When I try to call it as import Person, it works on Jupyter cell but I can not access the functions inside of it.
For example, if you tried writing this in Jupyter Notebook you might get this message after typing this
Person.myfunc('ds')
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-60-63fdc0f35859> in <module>
----> 1 Person.myfunc('ds')
AttributeError: module 'Person' has no attribute 'myfunc'
My Advice
Restart your kernel and this should eliminate this problem. I hope this clarifies your question as well could be considered as an answer.
Just restart the kernel and it should work fine :)
Firstly, if you're already working with other files, I recommend that you stop using jupyter and even terminal aswell.
You can use Pycharm instead.
If you were just learning, you could use jupyter but if you're already at that stage I recommend you to stick to Pycharm.
Pycharm is a nice IDE, where you can run the files directly on it, and has a lot more cool features.
Also, to use it in jupyter, just import the files you want:
import #whatever file you want

Categories

Resources