How do I import pcap or pyshark on python - 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'],

Related

Python 3: No module named 'tqdm'

I am using Raspberry PI 3 Model B running Kali Linux and i am currently coding a P2P encrypted python chat that runs on python 3. The cryptographic library i am using is called "CryptoShop", which is a '.py' file, not a imported library. I use it the same way that it's 'README' file instructed, so this is not a thing. Before i adeed crypto to the chat, it worked well, but now, i'm having errors since CryptoSHop uses the TQDM math library, and tryed installing it using APT-GET, PIP, by Source and nothing, because, firstly my chat only runs on Python3:
root#kali:~# python PyChat/pychat.py
File "PyChat/pychat.py", line 16
SyntaxError: Non-ASCII character '\xc3' in file PyChat/pychat.py on line 16, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
So when i use Python3:
root#kali:~# python3 PyChat/pychat.py
Traceback (most recent call last):
File "PyChat/pychat.py", line 4, in <module>
from cryptoshop import encryptstring
File "/root/PyChat/cryptoshop.py", line 52, in <module>
from tqdm import *
ModuleNotFoundError: No module named 'tqdm'
CryptoSHop try importing tqdm.
Here's a piece of it's code:
import os
import sys
from tqdm import *
import getpass
import argparse
I am still on the level of basic coding, i get this piece of chat code on the web, and just adeed to it basic user authentication (check if file whit the username exists), improved usability, and adeed crypto.
And sorry by my bad english, it's not my native language ;-)
Thanks in advance.
I am spanish, this happend when you use acents or special charts.
Add this in your first line:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
And use pip3 for install tqdm in python3
pip3 install tqdm

Importing Request library in Python

I am trying to use the Python Library requests using Liclipse. I have added the library but it is giving me the below error message
Traceback (most recent call last):
File "C:\programming\automate_boring_stuff\test.py", line 1, in <module>
import requests
File "C:\programming\libraries\kennethreitz-requests-> > 00fa5f1\requests\__init__.py", line 3, in <module>
from . import ssl_match_hostname
ImportError: cannot import name ssl_match_hostname
Unusually I was previously using it on another computer and it worked finebut on this one by just running import requests it gives me the above error message.
I have tried researching this but most of the answers I have found have been related to different libraries and I could not find how the fixes related to the requests library.
You have mucked up your installation; you appear to have moved the requests/packages/urllib3/packages/__init__.py file into the top-level requests folder.
Remove the package and re-install.

Installed Twitter module for python cannot be imported

$ python3 setup-py install
....
Installed /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/twitter-1.17.1-py3.5.egg
Processing dependencies for twitter==1.17.1
Finished processing dependencies for twitter==1.17.1
$ python3 twitter.py
Traceback (most recent call last):
File "twitter.py", line 1, in <module>
from twitter import Twitter
File "/Users/eddiee/2_python/twitter.py", line 1, in <module>
from twitter import Twitter
ImportError: cannot import name 'Twitter'
What might cause the problem:
Due to the restrictions of the preinstalled python on Mac, I installed another new python and changed the path. But I don't know how to install the module to the new python.
Eddie:
Try to change the import line to:
import twitter
or:
from twitter import Twitter
Hope it helps.
The problem here is I names my file as "twitter.py". When I imported the twitter module, python automatically imported the file itself, because the current file has a higher priority over the module. Simply changing the file name can solve the problem.

Python/twisted importing twisted.internet.endpoints on windows

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.

Error during library import in Python (Windows)

I am trying to configure svn hook for email notification using mailer.py script from apache, but it always crash on import of svn libs. I try two ways of installing svn and python. I try to install everything manually using command line and use CollableNet installer that have preinstalled Python and all libs I need but result is the same.
Now I try to import one library from hole package that I need using python in command line and I have such response:
>>> import svn.core
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named svn.core
I try to fix it using:
1) import sys; sys.path.append("C:\csvn\lib\svn-python\svn")
and
2) C:\csvn\lib\svn-python\svn>python "\__init__.py" install
But it didn't help.
For now I have no package with setup.py to install it.
I spend a lot of time on this task, and going crazy a little). Please give me any suggestion how to fix it.

Categories

Resources