如何解决'py' 未被识别为内部或外部命令
我不明白为什么我的代码失败并阅读了其他一些类似的帖子,但修复程序不起作用。我会预先说我的计算机上安装了 Python 3 和 Anaconda。我正在尝试运行以下 .bat 文件,但是当它到达 @py 和 python 文件时,它给了我问题标题中的错误。这是 .bat 文件:
@echo off
:: BatchGotAdmin
:-------------------------------------
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
REM --> If error flag set,we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
set params = %*:"=""
echo UAC.ShellExecute "cmd.exe","/c %~s0 %params%","","runas",1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
exit /B
:gotAdmin
pushd "%CD%"
CD /C "%~dp0"
:--------------------------------------
@py C:\Users\mikha\PycharmProjects\DataCamp\IntroToPython\PullPardotContacts.py
pause
我看到另一个帖子,有人提到将 py 更改为 python。其他人告诉他他很愚蠢,但这实际上解决了上述问题。我不明白为什么,所以也许有人会对此有所了解。但是,我随后收到以下错误。
The filename,directory name,or volume label syntax is incorrect.
Traceback (most recent call last):
File "C:\Users\mikha\PycharmProjects\DataCamp\IntroToPython\PullPardotContacts.py",line 2,in <module>
import pypardot
File "C:\Users\mikha\anaconda3\lib\site-packages\pypardot\__init__.py",line 3,in <module>
from pypardot.client import PardotAPI
File "C:\Users\mikha\anaconda3\lib\site-packages\pypardot\client.py",line 54
except PardotAPIError,err:
^
SyntaxError: invalid syntax
Press any key to continue . . .
所有需要安装的东西都已安装,但我仍然收到错误消息。我有一个朋友运行相同的代码,它对他有用,但不适合我,让我认为问题是设置问题,而不是编码问题。但是,这里还有一些更详细的代码:
import csv
import pypardot
from datetime import date
from pypardot.client import PardotAPI
import schedule
now = date.today()
dt_string = now.strftime("%d_%m_%Y")
filepath = 'Pardot_Prospect_Data_' + dt_string + '.csv'
p = PardotAPI(
email='info@email.com',password='fsgfsdfsdfgsdfsgdf',user_key='ddb183cgdfgsdfgsrger2454234'
)
'this is the api link'
p.authenticate()
prospects = p.prospects.query()
total_prospects = prospects['total_results']
print(total_prospects)
'store data a dump'
data_dump = p.prospects.read_by_email(email='info@hyperfine.io')
'print(prospects)'
batch = 0
count = 0
data_file = open(filepath,'w',encoding='utf-8',newline="")
csv_writer = csv.writer(data_file)
header = ['id','campaign_id','salutation','first_name','last_name','email','password','company','website','job_title','department','country','address_one','address_two','city','state','territory','zip','phone','fax','source','annual_revenue','employees','industry','years_in_business','comments','notes','score','grade','last_activity_at','recent_interaction','crm_lead_fid','crm_contact_fid','crm_owner_fid','crm_account_fid','salesforce_fid','crm_last_sync','crm_url','is_do_not_email','opted_out','is_reviewed','is_starred','created_at','updated_at','campaign','Prospect_Type','Web_Form_Interest','MQL_Date']
csv_writer.writerow(header)
data_file.close()
while batch <= total_prospects:
prospects = p.prospects.query(offset=batch)
data_file = open(filepath,'a',newline="")
csv_writer = csv.writer(data_file)
for item in prospects['prospect']:
id = str(item['id'])
campaign_id = str(item['campaign_id'])
salutation = item['salutation']
first_name = item['first_name']
last_name = item['last_name']
job_title = item['job_title']
email = item['email']
password = item['password']
company = item['company']
website = item['website']
job_tile = item['job_title']
department = item['department']
country = item['country']
state = item['state']
territory = item['territory']
address_one = item['address_one']
address_two = item['address_two']
city = item['city']
zip = str(item['zip'])
phone = str(item['phone'])
fax = item['fax']
source = item['source']
annual_revenue = item['annual_revenue']
employees = item['employees']
industry = item['industry']
years_in_business = item['years_in_business']
comments = item['comments']
notes = item['notes']
score = str(item['score'])
grade = item['grade']
last_activity_at = item['last_activity_at']
recent_interaction = item['recent_interaction']
crm_lead_fid = item['crm_lead_fid']
crm_contact_fid = item['crm_contact_fid']
crm_owner_fid = item['crm_owner_fid']
crm_account_fid = item['crm_account_fid']
salesforce_fid = item['salesforce_fid']
crm_last_sync = item['crm_last_sync']
crm_url = item['crm_url']
is_do_not_email = item['is_do_not_email']
is_do_not_call = item['is_do_not_call']
opted_out = item['opted_out']
is_reviewed = item['is_reviewed']
is_starred = item['is_starred']
created_at = item['created_at']
updated_at = item['updated_at']
campaign = item['campaign']['name']
if 'Prospect_Type' in item:
Prospect_Type = item['Prospect_Type']
else:
Prospect_Type = '-'
if 'Web_Form_Interest' in item:
Web_Form_Interest = item['Web_Form_Interest']
else:
Web_Form_Interest = '-'
if 'MQL_Date' in item:
MQL_Date = item['MQL_Date']
else:
MQL_Date = '-'
row = [id,campaign_id,salutation,first_name,last_name,email,password,company,website,job_title,department,country,address_one,address_two,city,state,territory,zip,phone,fax,source,annual_revenue,employees,industry,years_in_business,comments,notes,score,grade,last_activity_at,recent_interaction,crm_lead_fid,crm_contact_fid,crm_owner_fid,crm_account_fid,salesforce_fid,crm_last_sync,crm_url,is_do_not_email,opted_out,is_reviewed,is_starred,created_at,updated_at,campaign,Prospect_Type,Web_Form_Interest,MQL_Date]
csv_writer.writerow(row)
batch += 200
data_file.close()
print("FINISHED")
exit()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。