简体   繁体   English

将目录添加到 PyCharm 中的 Python 路径?

[英]Add directory to Python path in PyCharm?

I want to be able to use the paraview.simple library in PyCharm.我希望能够在 PyCharm 中使用paraview.simple库。 I already have paraview installed in my computer.我的电脑上已经安装了paraview。 This package cannot be installed with pip and there are no .whl files as far as I can tell.这个包不能用pip安装,据我所知没有 .whl 文件。 The website docs recommend that the directory containing all the python files be added to PYTHONPATH.网站文档建议将包含所有 python 文件的目录添加到 PYTHONPATH。

How do I add the relevant folder in PYTHONPATH on my PyCharm session, and keep it there by default, such that when I close out and reopen the paraview.simple library is still available?如何在 PyCharm 会话的 PYTHONPATH 中添加相关文件夹,并默认将其保留在那里,以便当我关闭并重新打开paraview.simple库时仍然可用?

You can add custom paths this way.您可以通过这种方式添加自定义路径。

  • Go to File->Settings->project Interpreter转到文件->设置->项目解释器
  • In the Project-Interpreter field, click the down facing arrow and select "show All"在 Project-Interpreter 字段中,单击向下的箭头并选择“全部显示”
  • In that Menu, highlight your interpreter and then in the right menu, select the button "Show paths for the selected interpreter" (this is the last button)在该菜单中,突出显示您的解释器,然后在右侧菜单中,选择“显示所选解释器的路径”按钮(这是最后一个按钮)
  • click the plus symbol to add your path单击加号以添加您的路径

Adding interpreter paths in PyCharm:在 PyCharm 中添加解释器路径:

  1. Project Settings/Project Interpreter: select "settings" icon项目设置/项目解释器:选择“设置”图标
  2. Project Interpreters: select "tree" icon项目解释器:选择“树”图标
  3. Interpreter Paths: select "plus" icon解释器路径:选择“加号”图标

截图

In PyCharm version 2020.3.1 use the following workflow instead (see official docs ):在 PyCharm 版本 2020.3.1 中,请改用以下工作流程(请参阅官方文档):

Ctrl+Alt+S - open Settings. Ctrl+Alt+S - 打开设置。

File|Settings|Project|Project Structure...文件|设置|项目|项目结构...

You will see project folder structure.您将看到项目文件夹结构。 Mark subfolders as Sources or Excluded将子文件夹标记为来源或排除

文件|设置|项目|项目结构

  • Use anaconda with Pycharm在 Pycharm 中使用 anaconda
  • To install paraview with anaconda run the following command: conda install -c conda-forge paraview要使用 anaconda 安装 paraview,请运行以下命令: conda install -c conda-forge paraview
  • If conda command is not recognized then register the Anaconda path to environment variable如果无法识别 conda 命令,则将 Anaconda 路径注册到环境变量
  • Now open pycharm and give the configuration path as the Anaconda path现在打开pycharm,将配置路径指定为Anaconda路径
  • File -> Settings -> Project Interpreter文件 -> 设置 -> 项目解释器
  • In Project Interpreter give similar path : "C:\\Users\\username\\Anaconda3\\python.exe"在项目解释器中给出类似的路径:“C:\\Users\\username\\Anaconda3\\python.exe”

For me this solved it: mapping the local path to the remote inside the Pycharm run configurations settings.对我来说,这解决了它:在 Pycharm 运行配置设置中将本地路径映射到远程。

Edit Configurations > Path Mappings >编辑配置 > 路径映射 >

Local path = /<Users/me/pycharm etc.../project root> remote path = /本地路径 = /<Users/me/pycharm etc.../project root> 远程路径 = /

eg.例如。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM