I have a python code which runs fine when I run it through the cmd using python filename.py
But when I create exe file using pyinstaller the exe file opens and prints an exception I made(see at the bottom of the code) says no module name pandas.
Then, If I edit the code and import pandas and recreate the exe file it will work.
Does anyone have an idea?
I'm not using pandas in the code, and even PyCharm marks the import pandas line as redundant.
I have Windows 10 and anaconda installed.
Thank you
import csv,re
import os.path, time, datetime
import subprocess
import sys
try:
nameOfTitle= "name"
SName="S"
os.chdir(r'someaddress')
summaries_csv_path="summaries.csv"
HtmlPath='html/-----.htm'
HtmlPathNoDir='-----.htm'
HtmlPathNoDirC='----.htm'
HtmlPathNoDir='-----.htm'
sub="name"
headerH3="------"
dataWlCsv="raw.zip"
opRow = 0
sumRow = 0
col_num=0
innerCount=0
x = 0
headerList = list()
htmlfile = open(HtmlPath,"w")
execfile(r'some address')#header
readOp = csv.reader(open(r'some address.csv'),delimiter=',')
for row in readOp: # Read a single row from the CSV file
execfile(r'\some address.py')#logic
execfile(r'some address.py')#footer
except:
e = sys.exc_info()[1]
print("<p>Error: %s</p>" % e)
print "IN "+" MODUL!"
Related
I have a python code that uses subprocess to open another python file that has been converted to an executable file. I want to be able to pass a string in the form of a SQL query like SELECT * FROM TABLE.
So I have created a variable string called PARAM that has the value "SELECT * FROM TABLE".
This is the .py making running the subprocess:
import pandas as pd
import subprocess
import re
param = "Select * from Table"
send = subprocess.Popen(["C:\\Users\\example\\Desktop\\testing.exe",param],stdout=subprocess.PIPE).communicate()[0].decode()
print(send)
However for some reason I do not get back the output from the .py file that has been made in to an executable.
Here is the code for the executable:
from sys import argv
import requests as rq
from requests_kerberos import HTTPKerberosAuth, OPTIONAL
def get_hypercube(query):
#param = "select 1 as Id, 'Test' as Name" #argv
url = 'https://example.com/csv/query'
kerberos_auth = HTTPKerberosAuth(mutual_authentication=OPTIONAL, delegate=True)
payload = "q=" + str(query)
r = rq.get(url, auth=kerberos_auth, params=payload, verify=False)
output = r.text
return output
result = get_hypercube(argv)
print(result)
But the send does not bring me the result of the exe file (RESULT). I must be missing something, or not fully understanding how subprocess works.
Any help much appreciated.
I generated an executable file with PyInstaller, but when I want to launch the application the console window shows me, that it couldn't find a directory or file. I checked the location and the folder "_MEI55762" is indeed not present.
Did anyone have this issue before?
Below the part of the code, where I think the error should be located. I think it has something to do with the imports of the "jsonrpclcient" package. I didnĀ“t post the full code with the all the GUI lines, since I think it will not help. If I am wrong please let me know.
import os
import sys
import requests
import json
import pyvisa
import time
from datetime import datetime
import threading
import signal
from jsonrpcclient import *
from jsonrpcclient.clients.http_client import HTTPClient
from jsonrpcclient.requests import Request
from tkinter import *
from tkinter import ttk
import traceback
print("-----------------------------------------")
print(" Q-Center V0.1 ")
print("-----------------------------------------")
port = ":8080"
rm = pyvisa.ResourceManager()
def listArticles():
for attempt in range (3): #Will be executed 3 times in case an error occurs
print('List Articles:')
try: #First try this
client = HTTPClient("http://" + ipEntry.get() + port)
response = client.send(Request("list_articles"), timeout=5)
print(response.data.result)
print('Success!')
except: #If an error occurs, call the print function and let the user know
print('An error occured!')
rebootPeacock()
else: #If no error occurs, stop trying
break
else: #If no attempt was successful, print that all 3 attempts failed. ONLY EXCUTED WHEN THE LOOP DOES'T BREAK.
print('All 3 attempts failed!')
answer = response.data.result
pkReply.insert(END, answer)
pkReply.insert(END, '\n\n')
The solution is to tell PyInstaller to add the "response-schema.json" file which is located at "C:\Users\pfra\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\jsonrpcclient".
So the command should look like:
pyinstaller --add-file "C:\Users\pfra\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\jsonrpcclient.response.schema.json;."
I have raspberry pi acting as MFRC522 card reader. So far I have a script which worked on python 2.7, but when I tried to move to python 3, bizarre thing happened.
I used updated library for it: https://github.com/pimylifeup/MFRC522-python and adjusted my script accordingly
I installed pip3 and spidev
Here is where strange thing happens. If I run demo script from repo above in new folder it works, cool.
But if I put my previous script in the same folder it returns error as below. And after that if I try again to run demo script, same error occurs.
Moving both script to different folder, has the same effect. I can run demo only before my script. Doing that after, is impossible.
Error:
File "/usr/lib/python3.7/re.py", line 297, in <module>
#functools.lru_cache(_MAXCACHE)
AttributeError: module 'functools' has no attribute 'lru_cache'
My script:
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
import time
import requests
import signal
import sys
import os
# some functions non related to MFRC522
reader = SimpleMFRC522()
while continue_reading:
try:
id, text = reader.read()
#print id
#print "---"
ver = query_server(id)
if ver == 1:
open_relay(5)
else:
#do something
finally:
time.sleep(0.5)
It's like folder is somehow tainted after firing my script, what am I missing?
I'm using the latest Gooey library on Python 2.7 on Windows as a GUI for a simple argparse, but for some reason, the script keeps giving me the [Errno2] No File Exists.
I think it is because there is a space in the path of the Anaconda installation (i.e. C:\Users\FirstName LastName\Etc.) but I'm stumped.
I have tried str.replace all the \ with \\, but I keep getting the same error message. Any ideas of what to do?
Code:
from __future__ import print_function
import pandas as pd
import numpy as np
import glob
import sys
import os
import json
from argparse import ArgumentParser
from gooey import Gooey, GooeyParser
#Gooey(program_name="CPT Lookup")
def parse_args():
stored_args = {}
parser = GooeyParser(description='CPT Lookup')
#Eventually make into checkboxes
parser.add_argument('year',
action='store',
default=stored_args.get('year'),
widget='FileChooser',
help="CSV file with extracted year")
parser.add_argument('CPT',
action='store',
default=stored_args.get('CPT'),
widget='TextField',
help='CPT Code')
args = parser.parse_args()
return args
def loadCSV(year):
#DO I DO SOMETHING LIKE YEAR.REPLACE('\','\\')?
df = pd.read_csv(year)
return df
if __name__ == '__main__':
conf = parse_args()
print("Opening CSV file")
sales_df = loadCSV(conf.year)
This was an issue with the Gooey library itself (I'm the author). It wasn't quoting incoming file paths correctly.
If you pull down the latest release from PyPi (pip install -U gooey), your example script should run without issue.
I am using PyCharm (1.5.4) as my python IDE on MacOS 10.6.4. I am tinkering with some code to manipulate stock price data. As part of that I want to import price data from yahoo by using the DataReader function that comes with Pandas 0.6.0. The code is as follow:
http://www.statalgo.com/2011/09/08/pandas-getting-financial-data-from-yahoo-fred-etc/
from pandas import ols, DataFrame
from pandas.stats.moments import rolling_std
from pandas.io.data import DataReader
import datetime
sp500 = DataReader("^GSPC", "yahoo", start=datetime.datetime(1990, 1, 1))
sp500_returns = sp500["adj clos"].shift(-250)/sp500["adj clos"] - 1
gdp = DataReader("GDP", "fred", start=datetime.datetime(1990, 1, 1))["value"]
gdp_returns = (gdp/gdp.shift(1) - 1)
gdp_std = rolling_std(gdp_returns, 10)
gdp_standard = gdp_returns / gdp_std
gdp_on_sp = ols(y=sp500_returns, x=DataFrame({"gdp": gdp_standard}))
sp500.plot()
gdp.plot()
When I run the code I get the following error:
Traceback (most recent call last):
File "/Users/MyName/PycharmProjects/test/mytest", line 3, in <module>
from pandas.io.data import DataReader
ImportError: No module named data
I see that PyCharm does not know how to unresolve the reference 'data'.
My python paths are set as follows:
import sys
from pprint import pprint as pp
pp(sys.path)
['/private/var/folders/st/stQUFIfOG28bmpY9dCspTk+++TI/-Tmp-',
'/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/site-packages/scikits.statsmodels-0.3.1-py2.7.egg',
'/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python27.zip',
'/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7',
'/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/plat-darwin',
'/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/plat-mac',
'/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/plat-mac/lib-scriptpackages',
'/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/lib-tk',
'/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/lib-old',
'/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/lib-dynload',
'/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/site-packages',
'/Library/Frameworks/EPD64.framework/Versions/7.1/lib/python2.7/site-packages/PIL']
What is puzzling is that PyCharm can resolve pandas.stats.moments but can't resolve pandas.io.data. I checked that both directories have the __init__.py file (the files are blank).
At this point I am not sure how to move forward. Greatly appreciate the help.
UPDATE:
$ cat __egginst__.txt
# egginst metadata
egg_name = 'pandas-0.3.0-3.egg'
prefix = '/Library/Frameworks/EPD64.framework/Versions/7.1'
installed_size = 1454562
rel_files = [
'EGG-INFO/pandas/__egginst__.txt',
'lib/python2.7/site-packages/pandas-0.3.0-3.egg-info',
Seems like deleting PyCharm's python interpreter configuration and re-configuring solved the problem. Strange... but fixed