I have installed tornado and following works fine, I am able to run hello,world app
python -c "import tornado"
but following results in error
python -c ""from tornado.netutil import TCPServer"
Import error
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: cannot import name TCPServer
full code : I am trying to run this https://gist.github.com/phuslu/1231481
You made the wrong imports from the wrong package, try the following:
import sys, os, re
import logging
from tornado.ioloop import IOLoop
from tornado.iostream import IOStream
from tornado.tcpserver import TCPServer
as your imports. I've tried and tested it.
Related
from twisted.internet.protocol import DatagramProtocol
from twisted.internet import reactor
results in the error message:
Traceback (most recent call last):
File "C:\Users\Pbaby\PycharmProjects\pythonProject1\pyfiles\for.py", line 1, in <module>
from twisted.internet.protocol import DatagramProtocol
File "C:\Users\Pbaby\PycharmProjects\pythonProject1\venv\lib\site-packages\twisted\internet\protocol.py", line 18, in <module>
from twisted.internet import defer, error, interfaces
File "C:\Users\Pbaby\PycharmProjects\pythonProject1\venv\lib\site-packages\twisted\internet\defer.py", line 42, in <module>
from typing_extensions import Literal, ParamSpec, Protocol
ImportError: cannot import name 'ParamSpec' from 'typing_extensions' (C:\Users\Pbaby\PycharmProjects\pythonProject1\venv\lib\site-packages\typing_extensions.py)
Process finished with exit code 1
PyCharm also shows warnings for
reactor.callInThread(...)
reactor.listenUDP(...)
reactor.run()
showing:
"Cannot find reference 'callInThread' in 'reactor.py'"
I have tried to reinstall the library with:
pip install --no-cache twisted
I've wrote some code which connects with DobotMagician and moves its arm. It was firstly made for Windows but due to some project requirements i switched to Raspberry pi 4B (windows with python 3.10 pycharm to linux with python 3.9.2 and Thonny IDE). I'm struggling to rewrite the code for Linux. I'm keep getting following error:
Traceback (most recent call last):
File "/home/XYZ/Desktop/dobot_composite/dobot_composite_demov-master/main.py", line 26, in <module>
ctypes.cdll('/michalsiniarski/Desktop/dobot_composite/dobot_venv/lib/python3.9/site-packages/magician_library', mode=ctypes.RTLD_GLOBAL)
TypeError: 'LibraryLoader' object is not callable
Part of code producing an error:
import os
import sys
from serial.tools import list_ports
import pandas
import ctypes
from ctypes import *
from magician_library import DoBotArm as Dbt
from magician_library import DobotDllType as dType
from magician_library import *
import numpy as np
import logging
import time
import threading
import multiprocessing
import subprocess as sub
import keyboard
homey_max=160
homex_min, homex_max=180, 274
a_max=2*homey_max
b_max=homex_max-homex_min
h_max, h_min=50, -60
resolution=1
homeX, homeY, homeZ=225, 0, h_max
#os.add_cdll_directory('/XYZ/Desktop/dobot_composite/dobot_venv/lib/python3.9/site-packages/magician_library')
ctypes.cdll('/XYZ/Desktop/dobot_composite/dobot_venv/lib/python3.9/site-packages/magician_library', mode=ctypes.RTLD_GLOBAL)
Commented out part os.add.cdll...is almost 1:1 line rewritten from Windows version (difference is cdll and dll), which also produces an error:
Traceback (most recent call last):
File "/home/XYZ/Desktop/dobot_composite/dobot_composite_demov-master/main.py", line 25, in <module>
os.add_cdll_directory('/XYZ/Desktop/dobot_composite/dobot_venv/lib/python3.9/site-packages/magician_library')
AttributeError: module 'os' has no attribute 'add_cdll_directory'
Guide I followed:
https://github.com/SERLatBTH/StarterGuide-Dobot-Magician-with-Python#starting-out
I'm really new to python and I don't have more ideas how to make this work or even if this possible at all :c
I installed Panda3D with this command:
pip3 install panda3d==1.10.6
Then I made main.py:
from direct.showbase.ShowBase import ShowBase
from panda3d.core import WindowProporties
class Game(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.Proporties = WindowProporties
self.Proporties.setSize(500, 500)
self.win.requestProperties(properties)
if __name__ == "__main__": Game = Game()
When I run this code it give error:
python3 __main__.py
Error:
Traceback (most recent call last):
File "__main__.py", line 2, in <module>
from panda3d.core import WindowProporties
ImportError: cannot import name 'WindowProporties' from 'panda3d.core' (/home/kali/.local/lib/python3.8/site-packages/panda3d/core.cpython-38-x86_64-linux-gnu.so)
I am using:
Kali Linux Live
Python 3.8.2
Thanks to everyone in advance
Seems like you have a typo in your import, try this:
from panda3d.core import WindowProperties
An application can't import the "urllib" module from the package "six". But I can import it from a test script in the same environment. Can't figure out why.
❯ nova
Traceback (most recent call last):
File "/usr/bin/nova", line 6, in <module>
from novaclient.shell import main
File "/usr/lib/python2.7/site-packages/novaclient/shell.py", line 45, in <module>
from novaclient import client
File "/usr/lib/python2.7/site-packages/novaclient/client.py", line 34, in <module>
from six.moves.urllib import parse
ImportError: No module named urllib
But if I run a simple test script, it's just fine:
#!/usr/bin/python2
from six.moves.urllib import parse
foo = parse.urlsplit("http://foo.net/florp/blorp?blap=blork")
print foo
Here's the output:
❯ ./test.py
SplitResult(scheme='http', netloc='foo.net', path='/florp/blorp', query='blap=blork', fragment='')
Tried setting my PYTHONPATH explicitly, tried it under virtualenv... nothing..
Any ideas? (Sorry I'm not a Python programmer, so it may be something obvious).
I've used these modules before, even in a Python script inside a folder where I have other working scripts. Here's my imports:
import os
import sys
import urllib.request as urllib, simplejson as json, requests
import subprocess
import Popen, PIPE
import time
I get this in my console:
Traceback (most recent call last):
File "party.py", line 4, in <module>
import urllib.request as urllib, simplejson as json, requests
ImportError: No module named request
How come? I've tried
sudo pip install request
..but with no luck. What is causing this?
what python version are you using? urllib.request seems to be python3
v2.7
>>> import urllib.request
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named request
>>>
v3.3
>>> import urllib.request
>>> urllib.request
<module 'urllib.request' from '/usr/lib/python3.3/urllib/request.py'>
>>>