Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
导入Python的库';s将Brython 3.7.5应用于Angular8项目的标准分布_Python_Python 3.x_Angular_Angular8_Brython - Fatal编程技术网

导入Python的库';s将Brython 3.7.5应用于Angular8项目的标准分布

导入Python的库';s将Brython 3.7.5应用于Angular8项目的标准分布,python,python-3.x,angular,angular8,brython,Python,Python 3.x,Angular,Angular8,Brython,我正在用Angular和Brython做第一个实验。一切都开始工作了,奇怪的是Python的标准库没有被认可。我很想知道为什么。 这是html部分(angular8中的index.html): 为什么,尽管链接了(大概是)Python的stdlib,树背仍然是: ImportError:没有名为os的模块 是我忘了放点别的东西,还是这个问题无法解决?在某种意义上,您不能在angular8中使用Brython?我怀疑中描述的搜索机制失败了: 问:我在运行时在浏览器控制台中看到很多404错误 布莱顿

我正在用Angular和Brython做第一个实验。一切都开始工作了,奇怪的是Python的标准库没有被认可。我很想知道为什么。

这是html部分(angular8中的index.html):

为什么,尽管链接了(大概是)Python的stdlib,树背仍然是:

ImportError:没有名为os的模块


是我忘了放点别的东西,还是这个问题无法解决?在某种意义上,您不能在angular8中使用Brython?

我怀疑中描述的搜索机制失败了:

问:我在运行时在浏览器控制台中看到很多404错误 布莱顿脚本,为什么

答:这是因为布莱顿实现“导入”的方式 机制。当脚本必须导入模块X时,Brython会搜索 不同目录中的文件或包:标准库 (Javascript模块的目录库,Python模块的目录库) 目录库/站点包,当前页面的目录。为此,, Ajax调用被发送到匹配的url;如果找不到该文件, 404错误消息写入浏览器控制台,但是 被布莱顿抓到,布莱顿继续搜寻直到找到 模块,或者如果所有路径都已尝试但没有 结果

这意味着安装不太正确。你有没有检查控制台有没有错误


有一页是:;简而言之,这些规则与普通Python的规则非常相似。

以下是对我有效的解决方案

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>BrythonAngular</title>
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link rel="preconnect" href="https://fonts.gstatic.com">
  <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--  Brython imports-->
  <script type="text/javascript"
    src="https://cdn.jsdelivr.net/npm/brython@3.9.3/brython.min.js">
</script>
<script type="text/javascript"
    src="https://cdn.jsdelivr.net/npm/brython@3.9.3/brython_stdlib.js">
</script>
</head>
<body class="mat-typography" onload = "brython()">
  <app-root></app-root>
  <script type="text/python">
  import os
  print(dir(os))
  </script>
</body>
</html>

布莱顿角
导入操作系统
打印(直接(操作系统))

“你他妈的说得对!”cit.我已经解决了我的问题!当我有时间的时候,我会发布完整的答案!你能简单地解释一下你是如何解决这个问题的吗?我也遇到过同样的问题,无法解决。@Johncowk已经有一段时间了,但是IIRC,我观察了使用浏览器中的“开发者”选项卡搜索网络流量的URL,然后在磁盘上移动内容,直到找到文件为止。
"scripts": [
    "src/assets/js/script.js",
    "src/assets/js/brython.js",
    "src/assets/js/brython_stdlib.js"
]
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>BrythonAngular</title>
  <base href="/">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link rel="preconnect" href="https://fonts.gstatic.com">
  <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--  Brython imports-->
  <script type="text/javascript"
    src="https://cdn.jsdelivr.net/npm/brython@3.9.3/brython.min.js">
</script>
<script type="text/javascript"
    src="https://cdn.jsdelivr.net/npm/brython@3.9.3/brython_stdlib.js">
</script>
</head>
<body class="mat-typography" onload = "brython()">
  <app-root></app-root>
  <script type="text/python">
  import os
  print(dir(os))
  </script>
</body>
</html>