I am using Ubuntu. I want to spam the bus and view the packets using Wireshark. I tried to run the Python code shown below, but it threw the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'can'
My code:
import time, can
bustype = 'socketcan'
channel = 'vcan0'
def producer(id):
# :param id: Spam the bus with messages including the data id.
bus = can.interface.Bus(channel=channel, bustype=bustype)
for i in range(10):
msg = can.Message(arbitration_id=0xc0ffee, data=[id, i, 0, 1, 3, 1, 4, 1], extended_id=False)
bus.send(msg)
# Issue #3: Need to keep running to ensure the writing threads stay alive.
time.sleep(1)
producer(10)
Ubuntu 18.04 and later
In Ubuntu 18.04 and later python-can and python3-can are provided by the default Ubuntu repositories. Open the terminal and type:
sudo apt update
sudo apt install python3-can # for Python 3.x
or
sudo apt update
sudo apt install python python-can # for Python 2.x
To install CANard (Library for interacting with Controller Area Network (CAN)) you must use pip.
python3 -m pip install --user CANard # for Python 3.x
or
python -m pip install --user CANard # for Python 2.x
Whenever you get the no module named '<module_name>' error in Python, it means that python can not find the module. Likely because module is missing.
You can install python modules using pip.
If you don't have the pip tool then you can install it using sudo apt install python-pip on Debian based operating systems.
In your case you need python-can module which can be install by using
pip install python-can
You need to install external third-party package python-can
You can do so using pip. Follow the instructions in the provided link
Related
I'm working on a web app django, when I install openbabel and try to import pybel i've got an error
I'm using a venv that was activate when I did all this commands
I install openbabel like this:
sudo apt-get install python-openbabel
I also tried :
sudo apt-get install openbabel libopenbabel-dev swig
Then I did :
pip install openbabel
after that, I've tried to import pybel (after importing openbabel)
This is actuall result :
>>> import pybel
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/etudiant/QuChemPedIA/QuChemPedIAProject/venv/lib/python3.5/site-packages/pybel.py", line 94, in <module>
descs = _getpluginnames("descriptors")
File "/home/etudiant/QuChemPedIA/QuChemPedIAProject/venv/lib/python3.5/site-packages/pybel.py", line 84, in _getpluginnames
return [x.split()[0] for x in plugins]
File "/home/etudiant/QuChemPedIA/QuChemPedIAProject/venv/lib/python3.5/site-packages/pybel.py", line 84, in <listcomp>
return [x.split()[0] for x in plugins]
IndexError: list index out of range
Any help please?
As #Manu mathew said, this is a bug, but not in Python's openbabel package but rather in the openbabel C library that it wraps (provided by the openbabel apt package).
The bug is fixed in version openbabel/2.3.2+dfsg-3 that for your Ubuntu Xenial (judging by your Python version) is not available.
So you need to upgrade your distro. The fix is available since Bionic but for best results, upgrade to the latest distro release (see below for explanation).
Beside that,
Installing python-openbabel apt package is useless because it's for Python 2. A package for Python 3 would be called "python3-openbabel" but there's no such package. So you do have to install the bindings from PyPI.
Installing a Python package both globally with apt-get and into venv with pip is redundant.
If you are using an old distro, you also open yourself to possible breakage when you link a new bindings package from PyPI against an old C library on your system. If the bindings package builds against your local library, it is likely meant to support this version, but who knows how much this combination was tested.
So normally, you should prefer the apt-get version of a Python package that wraps a local C library if one is available if you are using the system Python. You can make globally installed packages available in a venv by creating it with --system-site-packages.
But since in this case, there's no apt-get version of bindings available, you have to install the bindings from PyPI. In this case, you'd better have the C library version that corresponds to the bindings' version -- i.e. probably the latest -- since that combination was clearly extensively tested.
I am using windows 8 and python 3.6.1 I've done the following command in my cmd:
pip install cryptoshop
However, when I run the following python code:
from cryptoshop import encryptfile
from cryptoshop import decryptfile
result1 = encryptfile(filename="test", passphrase="mypassphrase", algo="srp")
print(result1)
result2 = decryptfile(filename="test.cryptoshop", passphrase="mypassphrase")
print(result2)
I get the following error:
Traceback (most recent call last):
File "C:/Users/Owner/Desktop/test.py", line 1, in
from cryptoshop import encryptfile
File "C:\Users\Owner\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cryptoshop__init__.py", line 26, in
from cryptoshop.cryptoshop import encryptfile
File "C:\Users\Owner\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cryptoshop\cryptoshop.py", line 56, in
from ._cascade_engine import encry_decry_cascade
File "C:\Users\Owner\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cryptoshop_cascade_engine.py", line 27, in
from ._nonce_engine import generate_nonce_timestamp
File "C:\Users\Owner\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cryptoshop_nonce_engine.py", line 39, in
import botan
ModuleNotFoundError: No module named 'botan'
Now, I obviously know that you must install botan into python in order to use it. However, this is where I am running into an issue. I've downloaded Botan from this link as instructed:
https://github.com/randombit/botan
And then I've followed these instructions in an attempt to install Botan:
./configure.py [--prefix=/some/directory]
make
make install
However, when I type make into the command line I get an error saying there is no such command. And then when I go to run my above Python code I still get the no module Botan error. So obviously I am doing something run. How can I properly install Botan into my Python 3.6 directories so that I can use cryptoshop.
I've also attempted to do pip install Botan, as that is how I've installed so many other python libraries but that has been unsuccessful as well.
make is a linux command
According to the botan website you can use nmake as a replacement on windows ( http://wiki.c2.com/?UsingNmake ) :
On Windows
You need to have a copy of Python installed, and have both Python and
your chosen compiler in your path. Open a command shell (or the SDK
shell), and run:
$ python configure.py --cc=msvc (or --cc=gcc for MinGW) [--cpu=CPU]
$ nmake
$ botan-test.exe
$ nmake install
Botan supports the nmake replacement Jom which enables you to run
multiple build jobs in parallel.
source : https://botan.randombit.net/manual/building.html
For completeness, here's how I made it work on a Mac
Assuming you have brew installed.
brew install botan
You may need to install other functionality first:
brew install gmp
brew install mpfr
brew install mpc
Find out where botan got installed with brew info botan.
My location is /usr/local/Cellar/botan/2.6.0
In that folder, you'll find lib/python2.7/site-packages, copy the contents of this folder into your Python's installation site-packages folder.
Note 1: At the time of this writing, only python 2.7 seems to be supported, but I'm using python 3.6 and everything seems to be working.
Note 2: If the file is called botan2.py, you may need to rename it to botan.py in your python's site-packages folder.
I have installed python 2.7.10 with PATH access and correctly installed twilio. However, when I try to execute a code I get this error message
Traceback (most recent call last):
File "C:\Users\tmslvo\Google Drive\Desktop\send text.py", line 1, in <module>
from twilio.rest import TwilioRestClient
ImportError: No module named twilio.rest
Now I read that a reason might be that python can't find the twilio package so I tried the
which -a python
which -a twilio
commands (in my Windows command prompt) in which case I get
'which' is not recognized as an internal or external command,
operable program or batch file.
Does anybody have an idea of what I'm doing wrong?
Thank you!
Twilio developer evangelist here.
I think your problem will be that somehow when you installed the library, it failed silently(?). A few things to keep in mind:
When installing Python libraries, always make sure you use pip.
Also, check that none of your files within the project are actually called twilio.py as this will conflict with the actual library.
Check that you're using the version of Python you think you're using by running python --version
All that failing, run the installation again, and all going well (without errors), you should be able to test it quickly with the following code.
import twilio
import twilio.rest
try:
client = twilio.rest.TwilioRestClient(account_sid, auth_token)
message = client.messages.create(
body="Hello World",
to="+14159352345",
from_="+14158141829"
)
except twilio.TwilioRestException as e:
print e
try this: sudo pip3 install twilio --upgrade
I had this problem as well.
In my case, I had named my file twilio.py and that is what caused the error.
Renaming the file to send_sms.py ( or any other name of your choice) will resolve the issue!
Close and then relunch all IDLE instances.
This sounds obvious but it worked for me, since the installations of components were successful
I ran into this same issue. I had used easy_install instead of pip to install twilio which was the problem. To fix this I ran pip uninstall twilio and reinstalled using pip.
rename file name other than twilio.py
EX:send_sms.py
A bit late to the party here but I also ran into this issue.
After some trial and error, it looks like it was due to the pip version I was using. I originally used -
pip3 install twilio.
Now I'm unsure of the underlying reason why this did not work, but it seems that pip3 does not encompass all versions of python 3.x? Using
pip3 list and
pip3.8 list
I noticed I had the twilio module for pip3 but not for pip 3.8.
I used the following and was able to solve the issue
pip3.8 install twilio.
I used pip3.8 because that matched the python3.8 version that I am using.
Pycharm user:
Macs (mid 2017) come with python 2.6 and 2.7 installed. PyCharm uses by default 2.6. When you install twilio (Pip install) the module is installed in python version 2.7. So, when you try to run twilio from PyCharm you get
ImportError: No module named twilio.rest
Solution: change the python interpreter in PyCharm. Go to preferences > project interpreter and from the drop menu Project Interpreter choose python 2.7
I think your pip is not configured properly . You may be getting succefuuly installed message but it is not install where it should be. try pip install --user i am sure it will work for you. pip install may work fine only in virtualenvironment without any config.Try pip install --user package name
#iosCurator
I had first installed twilio with the easy_intall tool
I followed the steps below:
Uninstall twilio with the command pip uninstall twillo
Install twilio with the command pip install twilio
Close the python IDLE and relaunch it.
For the windows user,
I have suggested, pip3 install twilio
Follow these steps (on mac):
Shift + Command + P
search: Configure Language Specific Setting
search: Python
add: "code-runner.runInTerminal": true
That's it!
Ask me any question about it by:
My LinkedIn
I ran into this issue when using poetry for my dependency management. Poetry doesn't recognise it as an existing package yet, hence it won't run your code unless you try the poetry+pip way.
there will be 2 reasons for this
1.make sure you kept right path for python files in environment location
2.install twilio
commands:
1.pip3 install twilio
(or)
pip install twilio
2.python otpv.py
this is my code :
import pcap ,struct
pack=pcap.pcap()
pack.setfilter('udp')
key=''
for recv_time,recv_data in pack:
recv_len=len(recv_data)
if recv_len == 102 and recv_data[42]== chr(02) and recv_data[101] == chr(03):
print struct.unpack('>I',recv_data[49:53])[0]
print '登陆了'
elif recv_len == 55:
print struct.unpack('>I',recv_data[49:53])[0]
print '登陆了'
and i use this to install pcap :sudo apt-get install python-libpcap , it installed ,
but when i run the code , it show error :
Traceback (most recent call last):
File "weapon.py", line 2, in <module>
import pcap ,struct
ImportError: No module named pcap
what can i do ,
thanks
For me on Ubuntu 10.04 the package is called python-libpcap:
sudo apt-get install python-libpcap
Then when I do:
import pcap
It works great!
I'm guessing the installed module doesn't match the version of python you're running.
Look in /usr/lib/python2.7/dist-packages/ and see if pcap is there (substituting the version you're using for 2.7).
You need to make sure that you have pip installed.
sudo apt-get install python-pip
Then you can install pypcap:
sudo easy_install pypcap
sudo pip install pypcap
I verified it for Ubuntu 14.10.
I'm trying to run a python application on my system. When I try to execute it I get a traceback which ends with something saying I need to install Xapian. So I went ahead an installed xapian-core and xapian-bindings using macports. Then I tried to run the python application again, but got the same traceback. Any ideas about what I should do next? Is there some kind of additional xapian-python thingy I need to install? This kind of thing is all new to me.
I'm using Mac OS 10.6.3, Python 2.6.5 and Django 1.2.1
Here are the last few lines of the traceback I get:
File "/Users/nick/dev/ymtest/../ymtest/lib/haystack/__init__.py", line 46, in <module>
backend = load_backend(settings.HAYSTACK_SEARCH_ENGINE)
File "/Users/nick/dev/ymtest/../ymtest/lib/haystack/__init__.py", line 21, in load_backend
return __import__('haystack.backends.%s_backend' % settings.HAYSTACK_SEARCH_ENGINE, {}, {}, [''])
File "/Users/nick/dev/ymtest/../ymtest/lib/haystack/backends/xapian_backend.py", line 18, in <module>
raise MissingDependency("The 'xapian' backend requires the installation of 'xapian'. Please refer to the documentation.")
haystack.exceptions.MissingDependency: The 'xapian' backend requires the installation of 'xapian'. Please refer to the documentation.
The following worked for me after having the same issue on OS X 10.5:
make a macports selfupdate:
sudo port selfupdate
install python 2.6 over macports
sudo port install python26
install python_select
sudo port install python_select
select python 2.6 as system default
sudo python_select python26
install xapian-core
sudo port install xapian-core
install xapian-bindings WITH PYTHON VARIANT
sudo port install xapian-bindings +python26
copy all your python libs from "/Library/Python/2.5/site-packages" to
"/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages"
wich is your new default site-packages folder!
restart Terminal
Done!