I want install libsoundtouch ("pip install libsoundtouch"). after install process, everything seems correct, but when I run my script python(2.7) can import this module.
After check I have files in "/usr/local/lib/python2.7/dist-packages/libsoundtouch".
#!/usr/bin/python
# -*- coding: utf-8 -*-
import libsoundtouch
./home/pi/myprog/scripts/python/test.py
Traceback (most recent call last):
File "./home/pi/myprog/scripts/python/test.py", line 5, in
import libsoundtouch
File "/usr/local/lib/python2.7/dist-packages/libsoundtouch/init.py", line 9, in
from zeroconf import Zeroconf, ServiceBrowser
File "/usr/local/lib/python2.7/dist-packages/zeroconf.py", line 189
def current_time_millis() -> float:
^
SyntaxError: invalid syntax
Related
I'm using the Requests library with Python 2.7 and get the following error:
Traceback (most recent call last):
File "/home/user/Documents/workspaces/controller/main.py", line 2, in <module>
import requests
File "/usr/local/lib/python2.7/dist-packages/requests/__init__.py", line 45, in <module>
from .exceptions import RequestsDependencyWarning
File "/usr/local/lib/python2.7/dist-packages/requests/exceptions.py", line 11, in <module>
from .compat import JSONDecodeError as CompatJSONDecodeError
File "/usr/local/lib/python2.7/dist-packages/requests/compat.py", line 14, in <module>
import charset_normalizer as chardet
File "/usr/local/lib/python2.7/dist-packages/charset_normalizer/__init__.py", line 24, in <module>
from .api import from_bytes, from_fp, from_path, normalize
File "/usr/local/lib/python2.7/dist-packages/charset_normalizer/api.py", line 38
sequences: bytes,
^
SyntaxError: invalid syntax
I installed Requests with the following command:
sudo pip install requests -t /usr/local/lib/python2.7/dist-packages
The file I'm running is just main.py with the content:
import json
import requests
if __name__ == "__main__":
print('hello world')
I have both Python 3.6 and 2.7 installed and selected Python 2.7 as the interpreter in VS Code.
I just ran into this issue; the package is expecting to be executed with Python 3, not Python 2.
Using cmd on windows 10 to run Python 2.7.16. When I run a .py file which imports scipy.py it comes up with the error:
"File "C:\Python27\scipy.py", line 18, in
from .python import string_types
ValueError: Attempted relative import in non-package"
As string_types should already be included in python, I don't understand why this error is happening and cant seem to get passed it. Does anyone know how to fix this?
you tried,
>>> from . import MyModule #MyModule.py
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: Attempted relative import in non-package
>>>
here . mean your current path
try,
from MyModule import *
now you can use string_types
or
import MyModule as m
m.string_types
I have a Python script which read and write a file with german umlauts (äöü) in an input file "myfile.in". I used Python version 2.7. Here a reduced version of my script:
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
if __name__=='__main__':
with open("myfile.in", "r") as f:
lines = f.readlines()
txt = ""
for line in lines:
txt = txt + line
with open("myfile.out", "w") as f:
f.write(txt)
This works fine.
Now I got the requirement from my customer to used the Future statement definitions and I added the following line to my Python script:
from __future__ import unicode_literals
Now I get the following error message:
Traceback (most recent call last):
File "myscript.py", line 9, in <module>
txt = txt + line
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 23: ordinal not in range(128)
How can I resolve this problem.
Thanks for your hints Thomas
I am using Scipy.stats to perform distribution fits on my data. It works perfectly on my machine. But when I package my script with Python source folder, python27.dll and try to run it on another machine (where python is not installed and I do not want to also) by invoking my script like below
Path/to/Python.exe Path/to/script.py
I get the follwing error
Traceback (most recent call last):
File "test2.py", line 2, in <module>
import scipy.stats
File "C:\Users\User\Desktop\Python27\lib\site-packages\scipy\stats\__init__.py
", line 344, in <module>
from .stats import *
File "C:\Users\User\Desktop\Python27\lib\site-packages\scipy\stats\stats.py",
line 173, in <module>
import scipy.special as special
File "C:\Users\User\Desktop\Python27\lib\site-packages\scipy\special\__init__.
py", line 636, in <module>
from ._ufuncs import *
ImportError: DLL load failed: The specified module could not be found.
My script is
import sys
import scipy.stats
import numpy
dataarray= [2.45, 3.67, 1.90, 2.56, 1.78, 2.67]
desc = scipy.stats.describe(dataarray)
print desc
This occurs only on Scipy import and scipy operations, all other imports and operations work fine. My purpose is to run this script in different machines without having to actually install python
This is really a simple script written in python, which I can run it normally on Linux. But when I moved it to Windows, there is a strange error. I wish some helps.
Before running the code, I have made some preparation for the environment:
1. Install Microsoft Visual C++ Compiler for python 2.7
2. Install python 2.7.11
3. pip install pyinstaller
4. easy_install pyshark
Below is part of my code.
# -*- coding: utf-8 -*-
from __future__ import print_function
import pyshark
import lxml
import os
def analysis_method(file_name):
cap = pyshark.FileCapture(input_file=file_name)
for packet in cap:
if hasattr(packet, "http"):
http_layer = packet["http"]
Below is the error information:
Traceback (most recent call last):
File "packet_offline_analysis.py", line 36, in analysis_method
for packet in cap:
File "C:\Python27\lib\site-packages\pyshark-0.3.6.1-py2.7.egg\pyshark\capture\capture.py", line 173, in _packets_from_tshark_sync
self._get_packet_from_stream(tshark_process.stdout, data, psml_structure=psml_structure))
File "C:\Python27\lib\site-packages\trollius-1.0.4-py2.7-win32.egg\trollius\base_events.py", line 300, in run_until_complete
return future.result()
File "C:\Python27\lib\site-packages\trollius-1.0.4-py2.7-win32.egg\trollius\futures.py", line 287, in result
raise self._exception
lxml.etree.XMLSyntaxError: Input is not proper UTF-8, indicate encoding !
Bytes: 0xD6 0xD0 0xB9 0xFA, line 6, column 58
Uninstall your Chinese version of Wireshark, and install a english version of Wireshark instead.
Then the problem is solved.