问题标签 [module-search-path]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
101 浏览

python - 为什么有模块搜索路径而不是输入目录名+输入文件名?

有优势吗?它是什么?

0 投票
4 回答
28276 浏览

python - 如何在 MacOS X 上添加 python 模块?

我正在尝试使用 pywn,这是一个用于使用 WordNet 的 python 库。我在 Windows 下玩过一点 python,但对 MacOS X 的东西完全陌生。我在 MacOS 10.5.8 下运行,所以我的默认 Python 解释器是 2.5.1

pywn 指令说:“将每个 .py 文件放在 python 搜索路径中的某个位置。”

MacOS X默认python安装下定义的python搜索路径在哪里?如果我将 pywn 文件放在 /Users/nick/programming/pywn 中,将其添加到搜索路径的最佳方法是什么?这是放置文件的最佳位置吗?

0 投票
2 回答
2884 浏览

python - 搜索路径是否比 sys.path 中的多?

我认为 sys.path 是 Python 模块的所有搜索路径的完整列表。

但是,在我的 Ubuntu 机器上,“/usr/local/lib/python2.6/dist-packages/”几乎是我所有模块所在的位置,并且该路径不在 sys.path 中。而且我仍然可以在该路径上导入任何模块。

编辑,不正确:即使我将 sys.path 设置为空列表,我仍然可以从该路径导入。

dist-packages 路径的隐含知识从何而来?在这个隐含的搜索路径组中是否还有其他路径,或者它是什么?

编辑:我的帖子的第二部分似乎不是真的。事实上,“sys.path = []”意味着我不能导入任何东西,甚至不能从我当前的工作目录中导入。我很抱歉。

0 投票
1 回答
2865 浏览

lua - How to set search paths allow lua addins as packages

tl;dr: I want to create lua packages with a custom directory name pattern, having problem with search paths.

The problem

I've got an application that I'm wanted to allow the user to write plugins for, following a similar model to Lightroom:

  • A default set of plugins are stored in <app data>/plugins/<name>.myplugin
  • <name>.myplugin is a directory bundle which may contain a set of scripts, binaries or other resources
  • A plugin may export many different functions to the app, via different scripts
  • The names of the exported functions are listed in an info.lua file that is read by the app

The problem I'm grappling with is how best to wrap the plugins as packages (modules + submodules) or regular scripts. I envisage that a plugin might include 3rd party modules:

If I set the package search path, package.path to include

then I can load the package with Foo=require 'Foo'. However, I can't work out how to get submodules loaded. If Foo.lua calls UsefulFunctions=require 'UsefulFunctions' then this load fails because lua's search path tries to look for UsefulFunctions.myplugin/UsefulFunctions.lua. I can't load it with require 'Foo.UsefulFunctions' either, for similar reasons.

Some options:

  • One workaround would be to explicitly add each plugin's path to the package path, but this would cause problems if two plugins each contained a submodule of the same name.
  • Another option is to write the plugins to use regular lua scripts rather than providing modules, but this still means that the search paths have to be set up inside each plugin.
  • A fallback option could be to lose the .myplugin suffix which would simplify the package search path.
  • Patch Lua to explicitly support this type of search path

Is there any way of providing the functionality I need?

I'm currently on Lua 5.1. I know 5.2 has more control over package search paths, but I don't think I have the option of updating to it at the moment. I'm also using luabind, though I don't think it is relevant to this.

0 投票
1 回答
160 浏览

jq - jq 包含默认搜索路径

我想在 /usr/lib/jq/mytest.jq 中放置一个函数定义,以包含在我的 jq 脚本中。

手册

默认搜索路径是指定给 -L 命令行选项的搜索路径,否则为 ["~/.jq", "$ORIGIN/../lib/jq", "$ORIGIN/../lib"]。

由于 jq 在 /usr/bin 中, /usr/bin/../lib/jq 不应该在搜索路径中吗?我无法让这个命令工作:

将 -L /usr/lib/jq 添加到命令中是可行的,或者我可以创建一个 ~/.jq/mytest.jq 并且也可以。但是,我想使用 ~/.jq 文件进行启动。如何在命令行上不指定 -L 的情况下拥有启动脚本包含搜索路径?

0 投票
1 回答
161 浏览

metadata - -I 有什么区别。和 Perl6 中的 -Ilib?

我有一个本地分布,如下所示:

两者都perl6 -I. -e 'use Foo;'编译perl6 -Ilib -e 'use Foo;'和运行,那么我应该使用哪一个,为什么?

0 投票
1 回答
92 浏览

python - 是否可以在 python 脚本中指定模块的搜索路径?如果是,我该怎么做?

我已经在 python 中编码了大约 2 个月,但我只熟悉基本的面向对象编程,所以我不太了解如何实现搜索模块之类的东西。(基本上我是菜鸟。)

我将一个名为 Opentrons Opentrons 2.5.2的包及其所有依赖项安装到与我当前正在编写的 python 脚本相同的文件夹中。但是,当我尝试导入下面的模块 [1] 时,我收到一条错误消息,指出“Opentrons 不是模块”。然后,我尝试将其转移到 python 库中,因为我使用 pprint 模块找到了搜索路径,并且它似乎可以工作。我想知道是否可以从 .py 文件本身指定搜索路径,而不是手动打印搜索路径并将文件放入脚本搜索的库中。(如果有帮助,愿意放入我放入 opentrons 包的目录的图像。)

[1]

编辑:我意识到我在位于 python 3.6 环境中的 Spyder 控制台中运行我的所有脚本这一事实可能很重要。