相关疑难解决方法(0)

在Python脚本中,如何设置PYTHONPATH?

我知道如何在我的/ etc/profile和我的环境变量中设置它.

但是如果我想在脚本中设置它呢?是导入os,sys?我该怎么做?

python unix linux environment-variables

102
推荐指数
4
解决办法
11万
查看次数

路径中找不到"dot.exe".Pydot on Python(Windows 7)

我在Windows 7上运行Python的pydot时遇到了麻烦.

我安装了pydot: conda install -c rmg pydot=1.2.2

我安装了graphviz ../Program Files (x86)/Graphviz2.38/

当我运行以下脚本时,我得到一个错误说

"dot.exe" not found in path
Run Code Online (Sandbox Code Playgroud)
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 …

python path pydot

22
推荐指数
3
解决办法
4万
查看次数

是否可以通过 serverless.yml 向 PATH 环境变量添加路径?

当我创建 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,而不是那种怪异的丑陋。

python amazon-web-services aws-lambda aws-lambda-layers

5
推荐指数
1
解决办法
1468
查看次数