我知道如何在我的/ etc/profile和我的环境变量中设置它.
但是如果我想在脚本中设置它呢?是导入os,sys?我该怎么做?
我在Windows 7上运行Python的pydot时遇到了麻烦.
我安装了pydot: conda install -c rmg pydot=1.2.2
我安装了graphviz ../Program Files (x86)/Graphviz2.38/
当我运行以下脚本时,我得到一个错误说
Run Code Online (Sandbox Code Playgroud)"dot.exe" not found in path
import pydot
graph = pydot.Dot(graph_type='digraph')
node_a = pydot.Node("Node A", style="filled", fillcolor="red")
node_b = pydot.Node("Node B", style="filled", fillcolor="green")
node_c = pydot.Node("Node C", style="filled", fillcolor="#0000ff")
node_d = pydot.Node("Node D", style="filled", fillcolor="#976856")
graph.add_node(node_a)
graph.add_node(node_b)
graph.add_node(node_c)
graph.add_node(node_d)
graph.add_edge(pydot.Edge(node_a, node_b))
graph.add_edge(pydot.Edge(node_b, node_c))
graph.add_edge(pydot.Edge(node_c, node_d))
graph.add_edge(pydot.Edge(node_d, node_a, label="and back we go again", labelfontcolor="#009933", fontsize="10.0", color="blue"))
graph.write_png('example2_graph.png')
Exception: "dot.exe" not found in path.
Run Code Online (Sandbox Code Playgroud)
我尝试过这个解决方案:https://stackoverflow.com/a/12257807/6561247
,添加my-paths.pth …
当我创建 AWS Lambda 层时,我的 zip 文件的所有内容/模块都会/opt/在 AWS Lambda 执行时转到。这很容易变得麻烦和令人沮丧,因为我必须对我所有的 lambda 使用绝对导入。例子:
import json
import os
import importlib.util
spec = importlib.util.spec_from_file_location("dynamodb_layer.customer", "/opt/dynamodb_layer/customer.py")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
def fetch(event, context):
CustomerManager = module.CustomerManager
customer_manager = CustomerManager()
body = customer_manager.list_customers(event["queryStringParameters"]["acquirer"])
response = {
"statusCode": 200,
"headers": {
"Access-Control-Allow-Origin": "*"
},
"body": json.dumps(body)
}
return response
Run Code Online (Sandbox Code Playgroud)
所以我想知道,是否可以通过 serverless.yml 预先将这些 /opt/paths 添加到 PATH 环境变量中?那样的话,我就可以from dynamodb_layer.customer import CustomerManager,而不是那种怪异的丑陋。