I am running a script inside Spyder that utilizes the multithreading library and the IPython console freezes with the output below. However, running the script using Windows command prompt via 'python quickstart11.py' works fine and generates the proper output.
runfile('C:/Python35/User/backtrader-master/docs/quickstart/quickstart11.py', wdir='C:/Python35/User/backtrader-master/docs/quickstart')
Exception in thread Thread-8:
Traceback (most recent call last):
File "C:\Anaconda3\lib\threading.py", line 914, in _bootstrap_inner
self.run()
File "C:\Anaconda3\lib\threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "C:\Anaconda3\lib\multiprocessing\pool.py", line 429, in _handle_results
task = get()
File "C:\Anaconda3\lib\multiprocessing\connection.py", line 251, in recv
return ForkingPickler.loads(buf.getbuffer())
AttributeError: Can't get attribute 'TestStrategy' on <module '__main__' (<_frozen_importlib_external.SourceFileLoader object at 0x000002727C461438>)>
I've tried adding freeze_support() according to Python doc, which should alleviate the problem, but it still freezes. What is going on?
Windows 10 64bit, Anaconda Python 35 64bit installer.
The problem is in Spyder. The kernel is running in interpreted mode and the addition of "freeze_support" doesn't happend before other things even if that's the intention, because the kernel is already running.
See here: https://github.com/mementum/backtrader/issues/118
Related
I have recently tried to install and get working a program developed to use with a telescope. It is called hubble-pi and can be found here. https://github.com/RemovedMoney326/Hubble-Pi
The program runs but when i click the capture button I get this issue. I have reached out to the dev but he has not replied and that was over a month ago. If anyone could assist in figuring out a solution that be awesome.
Im a beginner when it comes to python so be easy. This is also happening on boot up as this is the first thing im doing when turning on my RPI. I am running this on a RPI 4 2gb.
Python 3.7.3 (/usr/bin/python3)
>>> %Run AstroCam.py
Start
Capture
mmal: mmal_vc_component_enable: failed to enable component: ENOSPC
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.7/threading.py", line 917, in _bootstrap_inner
self.run()
File "/usr/lib/python3.7/threading.py", line 865, in run
self._target(*self._args, **self._kwargs)
File "/home/pi/AstroCameraApp/PythonScripts/AstroCam.py", line 60, in camHandler
camera.resolution = DynamicCaptureResolution #set photo size
File "/usr/lib/python3/dist-packages/picamera/camera.py", line 2282, in _set_resolution
self._enable_camera()
File "/usr/lib/python3/dist-packages/picamera/camera.py", line 1976, in _enable_camera
self._camera.enable()
File "/usr/lib/python3/dist-packages/picamera/mmalobj.py", line 724, in enable
prefix="Failed to enable component")
File "/usr/lib/python3/dist-packages/picamera/exc.py", line 184, in mmal_check
raise PiCameraMMALError(status, prefix)
picamera.exc.PiCameraMMALError: Failed to enable component: Out of resources
I just hit this same error with another Picamera IMX477 app, and found a fix.
Set gpu-mem=192 in /boot/config.txt, reboot, and 4032x3040 starts working.
This is for Pi-4, 2GB running Buster. Bullseye is a different animal.
I am writing a simple network scanner with python using scapy following is my code :
import scapy.all as scapy
def scan(ip):
scapy.arping(ip)
scan("192.168.1.1/24")
Error I am getting :
Traceback (most recent call last):
File "ipScanner.py", line 10, in <module>
scan("192.168.1.1/24")
File "ipScanner.py", line 8, in scan
scapy.arping(ip)
File "/Users/omairkhan/opt/anaconda3/lib/python3.7/site-packages/scapy/layers/l2.py", line 648, in arping
filter="arp and arp[7] = 2", timeout=timeout, iface_hint=net, **kargs) # noqa: E501
File "/Users/omairkhan/opt/anaconda3/lib/python3.7/site-packages/scapy/sendrecv.py", line 553, in srp
filter=filter, nofilter=nofilter, type=type)
File "/Users/omairkhan/opt/anaconda3/lib/python3.7/site-packages/scapy/arch/bpf/supersocket.py", line 242, in __init__
super(L2bpfListenSocket, self).__init__(*args, **kwargs)
File "/Users/omairkhan/opt/anaconda3/lib/python3.7/site-packages/scapy/arch/bpf/supersocket.py", line 62, in __init__
(self.ins, self.dev_bpf) = get_dev_bpf()
File "/Users/omairkhan/opt/anaconda3/lib/python3.7/site-packages/scapy/arch/bpf/core.py", line 114, in get_dev_bpf
raise Scapy_Exception("No /dev/bpf handle is available !")
scapy.error.Scapy_Exception: No /dev/bpf handle is available !
Exception ignored in: <function _L2bpfSocket.__del__ at 0x105984c20>
Traceback (most recent call last):
File "/Users/omairkhan/opt/anaconda3/lib/python3.7/site-packages/scapy/arch/bpf/supersocket.py", line 139, in __del__
self.close()
File "/Users/omairkhan/opt/anaconda3/lib/python3.7/site-packages/scapy/arch/bpf/supersocket.py", line 211, in close
if not self.closed and self.ins is not None:
AttributeError: 'L2bpfSocket' object has no attribute 'ins'
Can anyone please help understand it.
NOTE: I am running it on mac OS.
I wrote this exact program when I first started programming with matching syntax, and it ran correctly on my systems when run as administrator. I develop on Linux and Windows rather than Mac, but I will offer what I can.
Are you running this script through your IDE or calling it from the shell?
I recommend only running it from the shell. This simply gives you more control over the files like specifying which version of python the script is, and if you need administrative privileges for a script, you can elevate the script permissions in the shell.
Also, in my OS, I was taught to always use, and have experienced the mistakes of forgetting this, always add:
#!/usr/bin/env python
as the first line of every script. At least in Linux, it tells the PC how to treat the file (it tells it to treat the file as a python file--yes I acknowledge that its already running it as python). I would check to see if that is valid for MacOS file system.
Most of what I have recommended so far comes down to no /dev/bpf handle is available, only ever being an issue for me when I'm not running script as an administrator (although Linux states permission denied). And I shouldn't leave out that using Anaconda on Windows in the past (before I understood the structure of my file systems) prevented me from using common modules like pygame and scapy. I could only guess in that case Anaconda prevented the PC from knowing where to find every piece of that module by making the computer think it had its own one of that module under Anaconda directory when it was in a different PATH.
I have explored using threads with PySimpleGui but quite often the thread terminates
RuntimeError: main thread is not in main loop
I have tried running the "official" demos, forexample:
https://github.com/PySimpleGUI/PySimpleGUI/blob/master/DemoPrograms/Demo_Multithreaded_Long_Task_Simple.py
This gives me the runtime error when I run it locally. However when I run the same demo on trinket :
https://pysimplegui.trinket.io/demo-programs#/multi-threaded/multi-threaded-long-task-simple
It seems to run fine. I am using
windows 10
Anaconda
python 3.8
spyder 4.2 (IDLE)
I have also tried to run outside spyder (IDLE) with the same effect.
Full error message:
*Exception in thread Thread-8:
Traceback (most recent call last):
File "C:\Users\xxx\.conda\envs\python38\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Users\xxx\.conda\envs\python38\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\xxxx\Demo_Multithreaded_Long_Task_Simple.py", line 31, in long_operation_thread
window.write_event_value('-PROGRESS-', progress)
File "C:\Users\xxx\.conda\envs\python38\lib\site-packages\PySimpleGUI\PySimpleGUI.py", line 8940, in write_event_value
self.thread_strvar.set('new item')
File "C:\Users\xxx\.conda\envs\python38\lib\tkinter\__init__.py", line 365, in set
return self._tk.globalsetvar(self._name, value)
RuntimeError: main thread is not in main loop*`
When I click on my Python IDE's (IDEL, PyScripter) they will not even open. I tried typing python in the command prompt and this is what happened:
C:\>python
Traceback (most recent call last):
File "C:\Python27\ArcGIS10.5\lib\site.py", line 548, in <module>
main()
File "C:\Python27\ArcGIS10.5\lib\site.py", line 537, in main
aliasmbcs()
File "C:\Python27\ArcGIS10.5\lib\site.py", line 469, in aliasmbcs
codecs.lookup(enc)
File "C:\Python27\ArcGIS10.5\lib\encodings\__init__.py", line 85, in search_function
norm_encoding = normalize_encoding(encoding)
File "C:\Python27\ArcGIS10.5\lib\encodings\__init__.py", line 57, in normalize_encoding`enter code here`
encoding = str(encoding, "ascii")
TypeError: str() takes at most 1 argument (2 given)
Did you recently install ArcGIS? It looks to me like ArcGIS installed a few libraries, and overwrote your site.py, but it's using code that's meant for Python3 rather than Python2.7. The str function is capable of taking in 2 arguments in Python3 but not in Python2.
To get your Python to work again, you could try deleting the entire ArcGIS10.5 directory from your computer (or temporarily moving it to your desktop and seeing if that helps). You can also try running python -S in Command Prompt to run Python without importing site.py.
To try to get ArcGIS working, you might be able to install Python3, and reinstall ArcGIS using that.
Hopefully that helps!
Please, could you help? I am unable to get the python console started in PyCharm. Have played with all option available and have trawled through the documentation, but cannot figure this one out. Any help would be appreciated. Please find below the error I get in the console...
OS: Win 10
C:\Miniconda3\python.exe "C:\Program Files (x86)\JetBrains\PyCharm\helpers\pydev\pydevconsole.py" 64331 64332
Traceback (most recent call last):
File "C:\Miniconda3\lib\site-packages\traitlets\traitlets.py", line 526, in get
value = obj._trait_values[self.name]
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm\helpers\pydev\pydevconsole.py", line 526, in <module>
pydevconsole.start_server(pydev_localhost.get_localhost(), int(port), int(client_port))
File "C:\Program Files (x86)\JetBrains\PyCharm\helpers\pydev\pydevconsole.py", line 355, in start_server
interpreter = InterpreterInterface(host, client_port, threading.currentThread())
File "C:\Program Files (x86)\JetBrains\PyCharm\helpers\pydev\_pydev_bundle\pydev_ipython_console.py", line 25, in __init__
self.interpreter = get_pydev_frontend(host, client_port, show_banner=show_banner)
File "C:\Program Files (x86)\JetBrains\PyCharm\helpers\pydev\_pydev_bundle\pydev_ipython_console_011.py", line 488, in get_pydev_frontend
_PyDevFrontEndContainer._instance = _PyDevFrontEnd(show_banner=show_banner)
File "C:\Program Files (x86)\JetBrains\PyCharm\helpers\pydev\_pydev_bundle\pydev_ipython_console_011.py", line 318, in __init__
self.ipython = PyDevTerminalInteractiveShell.instance()
File "C:\Miniconda3\lib\site-packages\IPython\config\configurable.py", line 337, in instance
inst = cls(*args, **kwargs)
File "C:\Miniconda3\lib\site-packages\IPython\core\interactiveshell.py", line 512, in __init__
self.init_readline()
File "C:\Miniconda3\lib\site-packages\IPython\core\interactiveshell.py", line 1911, in init_readline
if self.readline_use:
File "C:\Miniconda3\lib\site-packages\traitlets\traitlets.py", line 554, in __get__
return self.get(obj, cls)
File "C:\Miniconda3\lib\site-packages\traitlets\traitlets.py", line 532, in get
% (self.name, obj))
traitlets.traitlets.TraitError: No default value found for None trait of <_pydev_bundle.pydev_ipython_console_011.PyDevTerminalInteractiveShell object at 0x00000000042CFBA8>
Process finished with exit code 1
Ok, after much twiddling about:
Changing the interpreter to a different version (to Python 3.5.x) made this work. This made me wonder if IPython was the issue.. and it sure was!!
The problem is that the IPython for Python 3.3.5 does not work with PyCharm. IPython Version 5 was installed by PyCharm, but does not work with Python 3.3.5.
I removed IPython using 'Conda uninstall' and then 'Conda clean' and restarted the console, it then worked like a charm...
In essence:
1. Exit Pycharm
2. Remove IPython - use 'Conda remove/uninstall' and then 'conda clean' to completely get rid of it.
3. Restart Pycharm and allow it reimport all 'skeletons'
4. Restart Console.
I had a similar problem on Fedora 24. For some reason Fedora still ships IPython 3.x :/ I simply upgraded it with pip3 install ipython --upgrade which installed IPython 6.0.0 and it works :D