pythonpath在哪_如何在Windows上编辑PYTHONPATH

pythonpath在哪

You are here because you are using:

您在这里是因为您正在使用:

  1. Windows OS version 10+

    Windows OS版本10+
  2. Python version 3.3+

    Python版本3.3+
  3. Anaconda3

    Python3

And you would like to edit your PYTHONPATH permanently.

您想永久编辑您的PYTHONPATH

TL; DR (TL;DR)

  1. Go to C:\Users\<your_username>\Anaconda3\Lib\site-packages

    转到C:\Users\<your_username>\Anaconda3\Lib\site-pa cks

  2. Create a file python37.pth

    创建一个文件python37.pth

  3. Edit the file to include this line C:\\Users\\<your_username>\\my_module

    编辑文件以包括此行C:\\Users\\<your_username>\\my_模块

加长版; 阅读 (The Long version; Do Read)

序幕 (Prologue)

In most cases, editing the PYTHONPATH from the Settings GUI will do the trick. The trick is well explained in this Stack Overflow answer.If in the first place you are only looking to edit your path locally, this helpful answer will do.

在大多数情况下,从设置GUI编辑PYTHONPATH 。 这个技巧在Stack Overflow答案中得到了很好的解释。如果首先,您只是想在本地编辑路径,那么这个有用的答案就可以了。

略有扩展 1个 (Slightly Extended Item no. 1)

If you don’t have C:\Users\<your_username>\Anaconda3\Lib\site-packages, replace C:\Users\<your_username> with the path to your Anaconda3.

如果您没有C:\Users\<your_username>\Anaconda3\Lib\site-pa您的C:\Users\<your_username>\Anaconda3\Lib\site-pa place C:\Users\<your_ ,请使用Anaconda3的路径place C:\Users\<your_用户名>。

略有扩展 2 (Slightly Extended Item no. 2)

If you are using Python3.7, create a file called python37.pth. Else create a file called python<XX&gt;.pth for whatever Python version you are using.

如果您使用的是Python3.7,请创建一个名为python37.pth的文件。 否则,为您使用的任何Python版本创建一个名为python<XX&g t; .pth的文件。

  • Not sure which version?

    不确定哪个版本?

    Under

    C:\Users\<your_username>\Anaconda3\ search for a file of the form python&lt;XX&gt;.dll. The <XX> indicates the version number you need for naming your .pth file.

    C:\Users\<your_username>\Anac onda3 \搜索form python&l t; XX&g t;.d ll的文件。 该<XX>表示您东东版本号d fo [R命名的.pth文件。

  • Windows is super annoying and won’t let you create a file with a .pth suffix?

    Windows非常烦人,不会让您创建带有.pth后缀的文件吗?

    There are such files in the

    在这些文件中

    C:\Users\<your_username>\Anaconda3\Lib\site-packages folder. Copy one of them and edit the prefix.

    C:\Users\<your_username>\Anaconda3\Lib\site-pa cks文件夹。 复制其中之一并编辑前缀。

  • Some places say you need to create a ._pth file instead of .pth?

    有些地方说,你需要创建一个._pth文件,而不是.pth

    A

    一个

    ._pth file will completely replace your existing path. While a .pth file will append its content to the path you already have. You can find more information here.

    ._pth文件将完全替换您现有的路径。 .pth文件会将其内容附加到您已有的路径中。 您可以在此处找到更多信息。

略有扩展 3 (Slightly Extended Item no. 3)

Assuming the SuperCoolClass you wish to import is located at C:\Users\<your_username>\my_project_folder\my_awesome_file.py .

假设您要导入的SuperCoolClass位于C:\Users\<your_username>\my_project_folder\my_awesome_f my_awesome_file.py。

Then open your newly created python<XX&gt;.pth file with your favorite text editor (please don’t say it’s Vim) and add one line:C:\\Users\\<your_username>\\my_project_folder.Yes, with those annoying double slashes \\ .No, without quotes "" .

然后使用您喜欢的文本编辑器(请不要说是Vim)打开新创建的python<XX&g t; .pth文件并添加line: C:\\Users\\<your_username>\\my_pr oject_folder。那些烦人的窦bl Ë斜杠\\。没有,才子ho UT引号“”。

And that’s it.Now you can import from anywhere, like a normal person:from my_awesome_file import SuperCoolClass .

就是这样,现在您可以像普通人一样从任何地方导入: from my_awesome_file import SuperCoolClass

结语 (Epilogue)

Nothing important to add here really. I just hope my 2 hours of frustration + 1 hour of writing this post saved you some time.Peace out.

没什么要添加的。 我只是希望我2个小时的沮丧+ 1个小时的撰写这篇文章可以节省您一些时间。

翻译自: https://www.freecodecamp.org/news/how-to-edit-pythonpath-on-windows-eafd19840d44/

pythonpath在哪

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值