Python/twisted importing twisted.internet.endpoints on windows - python

I am trying to write a server using twisted on python.
This is the head of my file :
from twisted.internet.protocol import Factory, Protocol
from twisted.internet.endpoints import TCP4ServerEndpoint
from twisted.internet import reactor
The first and the last import work perfectly. I get an error when trying to run the second import with the following traceback :
Traceback (most recent call last):
File "<ipython-input-1-c0d6286e105b>", line 1, in <module>
from twisted.internet.endpoints import TCP4ServerEndpoint
File "C:\Anaconda3\lib\site-packages\twisted-15.5.0-py3.4.egg\twisted\internet\endpoints.py", line 34, in <module>
from twisted.internet.stdio import StandardIO, PipeAddress
File "C:\Anaconda3\lib\site-packages\twisted-15.5.0-py3.4.egg\twisted\internet\stdio.py", line 30, in <module>
from twisted.internet import _win32stdio
ImportError: cannot import name '_win32stdio'
I've already tried solutions like installing pypiwin32 both manually (using whl file) and with pip install. But the problem is not solved.
I am working on windows 7 (yes !) with python 3.4.3 and Twisted 15.0
Thank you for your help.

You are using Python 3, and _win32stdio is not ported to Python 3. If you want the full set of Twisted functionality, you have to run Python 2 (PyPy 4.x+ recommended) for now.

You could install twisted-win with:
pip install twisted-win
From description:
Windows compatibility for Twisted, specifically for Scrapy
It works for me for win 7, python 3.5.2.

Related

Python ImportError: cannot import name urlencode

I've seen this question asked before but none of the answers seem to work for me.
I am using python version 2.7.13
In my code I have ..
import base64
import httplib2
Now when I run it on my own pc it works fine, but when I run it on my works p.c. behind a firewall I get ..
Traceback (most recent call last):
File "mail4.py", line 2, in
import httplib2
File "C:\Python27\lib\site-packages\httplib2__init__.py", line 39, in
import urllib
File "C:\mypy\urllib.py", line 1, in
import requests
File "C:\Python27\lib\site-packages\requests__init__.py", line 43, in
import urllib3
File "C:\Python27\lib\site-packages\urllib3__init__.py", line 8, in
from .connectionpool import (
File "C:\Python27\lib\site-packages\urllib3\connectionpool.py", line 35, in
from .request import RequestMethods>
File "C:\Python27\lib\site-packages\urllib3\request.py", line 10, in >
from .packages.six.moves.urllib.parse import urlencode
ImportError: cannot import name urlencode
I've tried setting proxies.
I've tried uninstalling and re-installing six
Also
from urllib.parse import urlencode
All to no avail ?
You are (in this case) apparently running Python 2.7.x, however parse module is in urllib package in Python 3.x. In Python 2.x its name was (just) urlparse. Based on that, I'd guess different configuration (mismatch in versions used between Code and/or 3rd party packages and/or python interpreter is behind the problem you're seeing).
EDIT: sorry, I should have also noticed you are looking for urlencode on the last bit. In python 2.7 that is a function in urllib module: from urllib import urlencode.
I fixed this issue with installing Werkzeug to <1.0, which removed the contrib module
pip install Werkzeug==0.16.1

Is aiopg supprted for python 3.6 now?

Today I tried to use new version of Python (3.6). I installed aiopg by pip (via PyCharm interpreter section tool).
And after I tried to import aiopg, exception was happend:
from aiopg.sa import create_engine
File "C:\Python36\lib\site-packages\aiopg\__init__.py", line 5, in <module>
from .connection import connect, Connection, TIMEOUT as DEFAULT_TIMEOUT
File "C:\Python36\lib\site-packages\aiopg\connection.py", line 4, in <module>
import fcntl
ModuleNotFoundError: No module named 'fcntl'
What is fcntl? It's linux python native module? In any case it does not work. Any solutions?
aiopg==0.11 has a regression but brand new aiopg==0.12 should work on Windows.

How do I import pcap or pyshark on python

I want to write the Ethernet packets capture while using python.
I googling and found that I should using Pcap library or PyShark but I try to import pcap, it said that can not found module name Pcap, so I try to using PyShark instance but it show like this on Python shell
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import pyshark
File "D:\Python27\lib\site-packages\pyshark-0.3.3-py2.7.egg\pyshark\__init__.py", line 1, in <module>
from pyshark.capture.live_capture import LiveCapture
File "D:\Python27\lib\site-packages\pyshark-0.3.3-py2.7.egg\pyshark\capture\live_capture.py", line 1, in <module>
from pyshark.capture.capture import Capture
File "D:\Python27\lib\site-packages\pyshark-0.3.3-py2.7.egg\pyshark\capture\capture.py", line 7, in <module>
import trollius as asyncio
ImportError: No module named trollius
About this problem, what should I do?
How can I import the library to python?
OS is Windows 8.1 and Python version 2.7.9
The pyshark project requires that trollius is installed for Python versions before Python 3.4. You'll need to install that separately.
It should have been installed when you installed the pyshark package however. Make sure to always use a tool like pip to install your packages and dependencies like these are taken care of automatically; the pyshark project declares the dependencies correctly:
install_requires=['lxml', 'py', 'trollius', 'logbook'],

import libvirt in python but ImportError on Ubuntu

My os is Ubuntu 12.04.
I install the kvm virt-manager and python.
I want to use python code to control the vm on kvm.
but my code import libvirt has something wrong...
Here is my code :
import libvirt
import time
import threading
import paramiko
import os
import commands
import signal
numVM = 1
hostname=['VM-01']
port=22
VMLoadAve={}
def monitor():
.....
while True:
monitor()
time.sleep(MAXDURATION)
Traceback (most recent call last): File "test1.py", line 1, in
import libvirt ImportError: No module named libvirt
I have installed the python-libvirt, libvirt-bin
what other reasons may do this happened?
I am a newest for this. thanks for your help ~ :)
For the sake of historicaly record, 'python-libvirt' is the correct deb package for the python 2 binding, while python3-libvirt gives you the corresponding python 3 binding to libvirt.

ImportError: cannot import name process (Twisted)

I'm using Mac OS X 10.9.1, and I remember installing Python some time ago (I can't remember why, given that Mac OS X comes with it). For some reason Twisted wasn't installed, so I installed Zope and Twisted.
I'm following this tutorial: http://www.raywenderlich.com/3932/networking-tutorial-for-ios-how-to-create-a-socket-based-iphone-app-and-server
The problem is, when I run this code:
from twisted.internet.protocol import Factory,Protocol
from twisted.internet import reactor
class IphoneChat(Protocol):
def connectionMade(self):
print "a client connected"
factory = Factory()
factory.protocol = IphoneChat
reactor.listenTCP(80, factory)
print "Iphone Chat server started"
reactor().run
I get this error:
Traceback (most recent call last):
File "/Users/Mattieman/Desktop/server.py", line 4, in <module>
from twisted.internet import reactor
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/twisted/internet/reactor.py", line 38, in <module>
from twisted.internet import default
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/twisted/internet/default.py", line 56, in <module>
install = _getInstallFunction(platform)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/twisted/internet/default.py", line 52, in _getInstallFunction
from twisted.internet.selectreactor import install
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/twisted/internet/selectreactor.py", line 18, in <module>
from twisted.internet import posixbase
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/twisted/internet/posixbase.py", line 53, in <module>
from twisted.internet import process, _signals
ImportError: cannot import name process
So I took a look in /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/twisted/internet
...and it appears that process.py is missing.
What do I do?
There seem to be other files missing as well, like _baseprocess.py
I used setup3.py, if it helps...
You're using Python 2.6. You shouldn't use setup3.py. You also shouldn't ever use a distutils setup.py-type script to install Python libraries into OS paths (like /Library/Frameworks/Python.framework/Versions/2.6/).
You may have a randomly corrupted Twisted installation on your system now (OS X itself ships with a copy of Twisted). Or you may just have some garbage in /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/twisted that you need to clean up. It's difficult to say which (which is why you should never use setup.py to install things - it leaves a big mess).
After you clean up that mess (I can't give you many tips on how to do this apart from "reinstall your OS X", sorry), you have a few options:
Use the version of Twisted distributed with your OS. Don't try to install a different version.
Treat your home directory as a simpler "virtual environment" and run setup.py install --user (--user tells it to leave its mess inside ~/.local where at least it won't ruin your OS install).
Create a virtualenv and install a new version of Twisted there
Of these, you probably want to go with virtualenv.
Also note that you shouldn't run setup3.py unless you're trying to install Twisted for Python 3. And if you're trying to do that then I'll warn you that only part of Twisted is ported - and it's a very small part. For example, it's not process support (hence the import error you're getting).

Categories

Resources