I've been trying to import Imutils for my Raspberry Pi project, and after moving the files of Imutils from my python 3.7 directory to my python 2.7 directory, I'm still having issues.
I got this error when trying to run my script :
Traceback (most recent call last):
File "main_script_test.py", line 18, in <module>
import imutils
File "/usr/local/lib/python2.7/dist-packages/imutils/__init__.py", line 8, in <module>
from .convenience import translate
File "/usr/local/lib/python2.7/dist-packages/imutils/convenience.py", line 5, in <module>
import numpy as np
File "/usr/local/lib/python2.7/dist-packages/numpy/__init__.py", line 292
SyntaxError: Non-ASCII character '\xef' in file /usr/local/lib/python2.7/dist-packages/numpy/__init__.py on line 293, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
I think this has to do with python not having the proper encoding info.
All suggestions are welcome!
moving the files of Imutils from my python 3.7 directory to my python 2.7 directory
This sounds... questionable. Modules are often written with a specific major version in mind because of various incompatibilities - in this case, the default source code encoding.
My first suggestion would be to try to install a Python 2.7 version of the imutils module, if it exists. If not, and if you're comfortable changing the source code, you can try to add # -*- coding: utf-8 -*- as the first line of the problematic file, which tells Python 2.7 which encoding to use.
Also, in case it's helpful, here's a similar question: Running Python 2.7 Code With Unicode Characters in Source
Related
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
I tried to install VIM-Latex using the Pathogen plugin on my machine which is running OSX Lion 10.7.5. I copied the downloaded VIM-Latex plugin files into my ~/.vim/bundle directory.
I also edited the .vimrc according to the instructions specified here.
However, I'm getting the following errors on trying to open a tex document in MAC Vim:
File "/Users/username/.vim/bundle/vim-latex-1.8.23-20130116.788-git2ef9956/ftplugin/latex- suite/outline.py", line 12, in <module>
import StringIO
ImportError: No module named StringIO
Error detected while processing /Users/username/.vim/bundle/vim-latex-1.8.23-20130116.788-git2ef9956/ftplugin/latex-suite/main.vim:
and
File "/Users/username/.vim/bundle/vim-latex-1.8.23-20130116.788-git2ef9956/ftplugin/latex-suite/pytools.py", line 1, in <module>
import string, vim, re, os, glob
ImportError: No module named string
Also, I ran a basic python script from the terminal that imported StringIO and string, and both seem to be getting imported just fine.
I'm not sure where the problem is here. Since I'm really new both with VIM and Installing Plugins, I'm not sure how I should go about debugging this issue, and so, any help will be precious!
Thanks!
StringIO and string are not available in Python 3.x. To make this code work, you have to run it with Python 2.x, e.g. Python 2.7.
The first two lines of the program are:
from i2clibraries import i2c_lcd
from ABElectronics_ADCPi import ADCPi
No matter what line is first the Pi returns an error when I attempt to run it under Python or Python 3. All the libraries are possessed and registered. Using the shell commands the checks saying the exports worked correctly all show up correctly. However, whatever line is line 1 will return a missing module error and the i2clibraries will always return a missing module error. By keeping that as the first line I get the least errors in running, but the program still returns this:
pi#raspberrypi ~ $ sudo python file.py
Traceback (most recent call last):
File "file.py", line 1, in <module>
from i2clibraries import i2c_lcd
File "/home/pi/i2clibraries/i2c_lcd.py", line 1, in <module>
from i2clibraries import i2c
File "/home/pi/i2clibraries/i2c.py", line 1, in <module>
from quick2wire.i2c import I2CMaster, writing_bytes, reading
ImportError: No module named quick2wire.i2c
Given the error, what possible solutions are there to stop the first line from being unable to find its module?
Problem
The error message is telling you that when you try to import the i2clibraries module, the imports that it requires (dependencies) cannot be found when it is itself is being imported. This is specifically in the first line of i2c.py file - where the line
from quick2wire.i2c import I2CMaster, writing_bytes, reading
is failing.
The problem is almost certainly that your modules are not on the Python module search path. Further info on this is given at the end of this answer should you need it.
Solution
There are a number of ways to resolve this. The one recommended by the developers of the module is
To use the library without installation, add the full path of the
source tree to the PYTHONPATH environment variable. For example:
export QUICK2WIRE_API_HOME=[the directory cloned from Git or unpacked from the source archive]
export PYTHONPATH=$PYTHONPATH:$QUICK2WIRE_API_HOME
So, you need to know where your quick2wire libraries are installed - from your error message, I would hazard a guess that they are in /home/pi/i2clibraries/, so $QUICK2WIRE_API_HOME=/home/pi/i2clibraries/ should be your first line of the above pair.
Further info
You can read more generally about how to install modules on Python 2.x on the Python website. You can look at what paths make up the module search path by going to an interactive Python prompt (i.e. typing python) and then doing.
>>> import sys
>>> sys.path
This will output a list containing strings representing all the paths that will be searched for modules.
I'm trying to do an standalone application with pyinstaller. The executable has just build fine, but when I´m trying to do some operations with functions integrated on library pyproj, the executable crashes.
The script runs fine on Pycharm, so I think that the problem is that pyinstaller is not linking with some kind of library of pyproj.
May I have to do something special with spec file or another thing to specify pyproj on the standalone application built with pyinstaller?
This is the error that Ihave obtained:
Traceback (most recent call last): File "<string>", line 6, in
<module> File "C:\pyproj\build\main\out00-PYZ.pyz\pyproj", line 343,
in __new__ File "_proj.pyx", line 85, in _proj.Proj.__cinit__
(_proj.c:1190)
RuntimeError: no system list, errno: 2
This is my "main.py"
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pyproj
print pyproj.__version__
p=pyproj.Proj(init='EPSG:4326')
Thanks in advance
The problem is that when using pyproj with PyInstaller, pyproj can not find the data files that are in the library folder.
The solution is to create a hook file, which will specify where the data files, so you can link them with our executable.
hook-pyproj.py
from PyInstaller.hooks.hookutils import collect_data_files
datas = collect_data_files('pyproj')
The hook file can be located on "hooks" folder on Pyinstaller installation or using the order --additional-hooks-dir, specifying a folder in which will be located "hook-pyproj.py"
Just threading on the previous answer, since 2014 there has been some refactoring on PyInstaller and here is the correct import line for the hook file above :
from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('pyproj')
from PyInstaller.hooks.hookutils import collect_data_files
datas = collect_data_files('pyproj')
This didn't worked for me. There were some errors in the executable again.
But I found in another thread that the problem can be solved with this:
from mpl_toolkits.basemap import pyproj as pyproj
pyinstaller seem to have problems to integrate the pyproj module itself, but basemap includes pyproj and is not ignored by pyinstaller.
Just for update
Somehow my python is broken and emits the error:
jseidel#EDP15:/etc/default$ python -c 'import random'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.6/random.py", line 47, in <module>
from os import urandom as _urandom
ImportError: cannot import name urandom
This is NOT the virtualenv error that is so commonly documented here and elsewhere: I don't use python directly, I have never setup a virtualenv explicitly, and there is no virtualenv directory or python script that I can find anywhere on my system.
I'm running Kubuntu 10.04 and until just recently my KPackageKit worked just fine and handled updates with no problem. Now it shows nothing... maybe because of this python error, maybe because of something else.
How do I go about finding the error and fixing python?
As suggested by #Armin Rigo, this worked for me:
1) Add a print 42 at the end of the /usr/lib/python2.6/os.py file.
2) If you see "42", then that is the correct os.py file and the urandom module is not include. Add the statement to include urandom (you can find a sample from another os.py file). This was what worked for me.
3) If you don't see "42", then that's not the os.py file that you're using. Find the random.py file that is crashing and insert import os; print os.__file__ to get more information about the failure.