I tried many ways to make my code executable and I tried (pypinstaller,py2exe,cx_Freeze) without any results, therefore I focused on py2exe and I solved almost all errors which I faced while using this way, but the last error as I attached below is very difficult to solve it and I wasted a lot of time to solve it and I didn't catch any result, when I tried to run the executable file I got a CMD window with the below error and it disappear quickly, kindly help me to solve it or inform me by a way is supporting (xlrd,openpyxl,selenium,xlsxwriter,pytesser) libraries to I use it to execute my code instead of py2exe,
Traceback (most recent call last):
File "semiFULLTWO.py", line 8, in <module>
File "openpyxl\ init .pyc", line 29, in <module>
File "openpyxl\workbook\ init .pyc", line 5, in <module>
File "openpyxl\workbook\workbook.pyc", line 17, in <module>
File "openpyxl\writer\write_only.pyc", line 23, in <module>
File "openpyxl\writer\excel.pyc", line 36, in <module>
File "openpyxl\packaging\extended.pyc", line 4, in <module>
ImportError: cannot import name _version_
the libraries which I'm using :
*# -*- coding: utf-8 -*-
import os
import time
import xlrd
import base64
import urllib
import requests
import openpyxl
import xlsxwriter
from PIL import Image
from lxml import etree
from io import BytesIO
from pytesser import *
from openpyxl import Workbook
from datetime import datetime
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select*
the error related to openpyxl lib :
only_date = str ( dt.date ( ) )
workbook = xlsxwriter.Workbook ( only_date + '.xlsx' )
worksheet = workbook.add_worksheet ( )
Related
When trying to import distance method from geopy.distance I am receiving the below error:
from geopy.distance import distance
File "C:\Users\cnethi\AppData\Local\Continuum\miniconda3\envs\airbnb\lib\site-packages\geopy\__init__.py", line 12, in <module>
from geopy.geocoders import * # noqa
File "C:\Users\cnethi\AppData\Local\Continuum\miniconda3\envs\airbnb\lib\site-packages\geopy\geocoders\__init__.py", line 120, in <module>
from geopy.geocoders.arcgis import ArcGIS
File "C:\Users\cnethi\AppData\Local\Continuum\miniconda3\envs\airbnb\lib\site-packages\geopy\geocoders\arcgis.py", line 5, in <module>
from geopy.compat import Request, string_compare, urlencode
File "C:\Users\cnethi\AppData\Local\Continuum\miniconda3\envs\airbnb\lib\site-packages\geopy\compat.py", line 56, in <module>
from urllib.request import (HTTPBasicAuthHandler, HTTPPasswordMgrWithDefaultRealm,
ImportError: cannot import name 'HTTPSHandler' from 'urllib.request'
Can anyone please help in fixing this issue with 'HTTPSHandler' in 'urllib.request' file?
Python version - Earlier it was 3.5.x. I saw a post saying that updating python would fix it, but it didnot. Current version is 3.7.7. Also, I am using a virtual environment.
Github link for urllib.request - https://github.com/python/cpython/tree/3.8/Lib/urllib/request.py - There is a HTTPSHandler class, but it is inside an if statement.
Sorry if this is a dumb question but I'm trying to import and open a CSV using pandas in Python. Whenever I hit run I get the syntax error "cannot import name 'unicode_literals'". I have no idea why that is happening and I haven't been able to find any source online which details what this error means.
This is my code:
import pandas as pd
with open(r"FILEPATH\File.csv") as rawData:
pd.read_csv(rawData)
Here is the Error:
C:\Anaconda3\python.exe "FILEPATH"
Traceback (most recent call last):
File "FILEPATH/Main.py", line 1, in <module>
import pandas as pd
File "C:\Anaconda3\lib\site-packages\pandas\__init__.py", line 7, in <module>
from . import hashtable, tslib, lib
File "pandas\src\numpy.pxd", line 157, in init pandas.hashtable (pandas\hashtable.c:22997)
File "C:\Anaconda3\lib\site-packages\numpy\__init__.py", line 107, in <module>
from __future__ import division, absolute_import, print_function
File "C:\Anaconda3\lib\__future__.py", line 23, in <module>
from __future__ import unicode_literals
ImportError: cannot import name 'unicode_literals'
cannot import name 'unicode_literals'
Any suggestions for why this isn't working would be greatly appreciated.
You're on the right track! The only thing you have to do is add another parameter to open(). This would yield:
import pandas as pd
with open(r"FILEPATH\File.csv", encoding='utf-8') as rawData:
pd.read_csv(rawData)
I'm just learning Python.
I have a file with the following content
import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web
If I name this file csv2.py and call:
python csv2.py
... it works. But if I name this file csv.py and run:
python csv.py
It triggers this exception:
C:\Git\algotrading [master ≡ +3 ~0 -0 !]> python csv.py
Traceback (most recent call last):
File "csv.py", line 2, in <module>
import matplotlib.pyplot as plt
File "C:\Users\andrerpena\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\pyplot.py", line 29, in <module>
import matplotlib.colorbar
File "C:\Users\andrerpena\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\colorbar.py", line 34, in <module>
import matplotlib.collections as collections
File "C:\Users\andrerpena\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\collections.py", line 36, in <module>
import matplotlib.mlab as mlab
File "C:\Users\andrerpena\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\mlab.py", line 172, in <module>
import csv
File "C:\Git\algotrading\csv.py", line 2, in <module>
import matplotlib.pyplot as plt
AttributeError: module 'matplotlib' has no attribute 'pyplot'
It took me like 40 minutes to figure out the problem. I mean.. Figure out the problem had to do with the name of the file.
Why is that happening?
It looks like matplotlib.pyplot through various imports needs mlab.py which calls "import csv". This should find a file (that is not yours) called csv but since you have renamed your file to csv.py it is attempting to import that instead, overriding the required import and messing up the import for matplotlib.pyplot.
csv.py is built into python and thus is restricted.
If you run a python interpreter and try to import csv, you'll succeed without having to download anything new.
Like igoldthwaite and Daniel Dobalian said:
If you create a file named: csv.py with the content:
import csv
print(csv)
And run:
python csv.py
You will see that this file import itself:
<module 'csv' from '/home/your/folder/csv.py'>
Also, if you do the same thing with other modules, you will find the same result:
import subprocess
print(subprocess)
Result:
<module 'subprocess' from '/home/your/folder/subprocess.py'>
And finally, if you do it with a file named matplotlib.py, you will get the same result:
import matplotlib
print(matplotlib)
# <module 'matplotlib' from '/home/your/folder/matplotlib.py'>
I have a script that starts like this with many imports:
from reportlab.graphics import shapes
from reportlab.lib.utils import ImageReader
from reportlab.graphics import barcode
from reportlab.lib.units import mm
from reportlab.pdfbase.pdfmetrics import stringWidth
import reportlab.rl_settings
import PIL
from cStringIO import StringIO
import labels
import pyodbc
import pandas
from os.path import expanduser
from time import sleep
import sys
I struggled massively with py2exe to even get an executable file. I finally managed it with the following setup script (most of which is just copy and pasted from similar issues and suggests on stackoverflow).
from distutils.core import setup
import distutils
import py2exe
import sys
import zmq
import os
sys.setrecursionlimit(5000)
distutils.core.setup(
options = {
"py2exe": {
"dll_excludes": ["MSVCP90.dll"]
}
},
)
sys.path.append('C:\\WINDOWS\\WinSxS\\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4148_none_5090ab56bcba71c2')
packages=[
'reportlab',
'reportlab.graphics'
'reportlab.lib.utils'
'reportlab.rl_settings'
'reportlab.lib.units'
'reportlabl.pdfbase.pdfmetrics',
],
os.environ["PATH"] = \
os.environ["PATH"] + \
os.path.pathsep + os.path.split(zmq.__file__)[0]
setup( console=[{"script": "working.py"}],
options={
"py2exe": {
"includes":
["zmq.utils", "zmq.utils.jsonapi",
"zmq.utils.strtypes"] } } )
I am sure my script is inelegant. It has three connected define functions and a final output.
try:
makeyourlabels()
except:
Print "Sorry, something went wrong."
I get an error when I run the file:
Traceback (most recent call last):
File "working.py", line 3, in <module>
File "reportlab\graphics\barcode\__init__.pyc", line 72, in <module>
File "reportlab\graphics\barcode\__init__.pyc", line 42, in _reset
File "reportlab\graphics\barcode\widgets.pyc", line 162, in <module>
File "reportlab\graphics\barcode\widgets.pyc", line 95, in _BCW
File "reportlab\lib\utils.pyc", line 243, in rl_exec
File "<string>", line 1, in <module>
File "<string>", line 1, in <module>
ImportError: No module named common
If anyone can make any sense of all this and get my .exe running, I would be ever grateful!
As there is no testable code in the question I can not guarantee this will fix your issue but I can explain why you get this error. It is because py2exe didn't bundle reportlab.graphics.barcode.common into your .exe.
How do I know this, I followed the traceback to see what Reportlab was doing in the rl_exec call, it turns out it is make this call using exec:
from reportlab.graphics.barcode.common import I2of5
But because the import is only done dynamically py2exe doesn't know about the need for this package.
So how do you fix it? Simply add 'reportlab.graphics.barcode.common' to your package list, that should help py2exe locate the module it is looking for.
I'm trying to run a script in python, and I'm getting an "invalid elf header" error. I have a series of scripts that call one another, I'll go ahead and include those as well:
import sys
sys.path.append("/home/smh/Linux/Desktop/gras-03-03/python")
from python_utilities import GRASTestor
which calls GRASTestor.py
from BaseTestor import BaseTestor
import numpy as np
import hepunit as unit
from gdml_writer import gdml_writer
from GDMLGeometryBuilder import GDMLGeometryBuilder
from GRASMacroBuilder import GRASMacroBuilder,GRASRMCMacroBuilder
from Plotters import Plotter
import os
import sys
import SpenvisCSVFileHandler
which calls SpenvisCSVFileHandler.py
import string
import Spenvis.so
import os
from numpy import *
which is where we get our error, specifically with the line "import Spenvis.so"
/home/smh/Linux/Desktop/gras-03-03/python/python_utilities
Traceback (most recent call last):
File "perform_gras_rmc_tests.py", line 6, in <module>
from python_utilities import GRASTestor
File "/home/smh/Linux/Desktop/gras-03-03/python/python_utilities/GRASTestor.py", line 19, in <module>
import SpenvisCSVFileHandler
File "/home/smh/Linux/Desktop/gras-03-03/python/python_utilities/SpenvisCSVFileHandler.py", line 8, in <module>
import Spenvis.so
ImportError: /home/smh/Linux/Desktop/gras-03-03/python/python_utilities/Spenvis.so: invalid ELF header
And I'm not certain why it's not working. Any suggestions would be appreciated!
Never mind. Upon looking at the file architecture, it appears the file Spenvis.so is mac specific for some reason. Just need to get the correct file, then.