I have been working for weeks using Eclipse's PyDev (Eclipse 3.8.1) and usually I click on files in Package Explorer to navigate through them. Now all of a sudden my Python project looks empty in the Package Explorer, just showing standard python libs.
I tried many things such as:
Refreshing project.
Importing again project to workspace.
Looking at custom filters in "customize view".
Opening project file in the editor and then using "link with editor".
Closing PyDev Package Explorer and opening it again.
Closing and opening Eclipse again (several times).
None of those showed the files. I don't know what is wrong with this project. I think it is not related, but it is also a git project.
Do you know what else is missing for me to try?
Thanks.
Found the solution in PyDev FAQ
The usual checks are:
In the PyDev Package Explorer menu, is the top level elements pointing to working sets, if yes, change it to "Project".
In the PyDev Package Explorer menu, customize view, the content has both, PyDev Navigator Content and Resources checked?
In the PyDev Package Explorer menu, customize view, is it possible that the filters selected are hiding all your elements?
The first item solved my problem.
This is a workaround. You could create a new working set and select the projects that you have created and wish to see them in the PyDev Package Explorer. This trick worked for me.
Steps to create a working set :
Click on the inverted triangle in the PyDec Package explorer.
Select "Select Working Set"
Click New button.
Select Resources and click Next
Select the projects that you wish to have them seen on the explorer -> mention a name of the working set and click Finish button.
Related
PyCharm's autocomplete isn't working for installed libraries. I have the following code:
from boto.emr.connection import EmrConnection
conn = EmrConnection(aws_keys.access_key_id, aws_keys.secret_key)
I want the editor to tell me what methods I have available to me when I press Ctrl+Space.
The boto library is installed in my environment, but it doesn't seem to be detected by PyCharm. How can I set this up correctly?
You've installed the 3rd-party library into a virtualenv, but PyCharm doesn't know about that by default. If nothing is specified, it will choose the system Python install as the interpreter. You need to go into the project settings and configure the interpreter to point at the virtualenv. PyCharm will then index the interpreter and allow you to autocomplete.
The virtualenv may be auto-detected in the dropdown menu on the left. If it is not, click the gear to the right, click "Add local", and select /path/to/virtualenv/bin/python (or \Path\to\virtualenv\Scripts\python.exe on Windows).
The above answer didn't work for me, because I wasn't able to find any project related setting in my setting,and the python Interpreter was empty.
The solution was to delete .idea file, from project root, close Pychram then go to project directory and open it with Pycharm:
$pycharm-professional or $pycharm-professional .
when it lunch a pop up window on the bottom right will appear and as you the following
select configure python interpreter then a new window must appear:
chose to use Pipenv as your interpreter or any other solution that is for your case.
Now the Project setting should appear again in Pycharm setting, and the recommendation must be already working.
Have been putting together applications that include their own infrastructure/deployment code using IntelliJ as my IDE. The total project as checked into Git includes several independent python scripts contained in sub directories under my project (including their package information and supporting python files). My IAC/deployment code takes care of making sure these scripts have a virtualenv with desired packages when on the infrastructure it is deployed to. All of this is working fine, except for when I try to get IntelliJ to understand the python subdirectory environments.
When I open the whole project tree as an IntelliJ project, there seems to be no way to explain to IntelliJ that some of the sub directories should be viewed as their own python project, such that they can have have their own virtualenv, packages, and base import directory understood. Being that IntelliJ doesn't understand these things, it sees my imports in these scripts as broken and I can't jump around in code etc.
As a work-a-round I have been sometimes just opening the python sub directories as their own IntelliJ project so that IntelliJ can understand them. But this is not ideal, as I have to have several different IntelliJ instances for the same larger project.
So now perhaps my question makes more sense, and I will restate it. Is there some way I am missing where I could have one instance of IntelliJ correctly understand the whole project including that some subdirectories are like python sub-projects with their own virtual env and packages etc?
A PyCharm/IntelliJ "project" can have "sub-projects". You access this feature by "attaching" one project to another. Open a project. Then open a second project. You'll get a dialog asking how you want to open the project, and one option will be "Attach". If you select this option, the second project is added to the already open window and your window now contains two somewhat independent projects.
If you now bring up the Preferences panel, and select "Project: xxx -> Project Interpreter", you should see that there are two projects listed in the central section of the panel. You can select each of these and configure the interpreter/environment settings for each project independently. You can also set up the Project Structure and Project Dependencies for each sub-project independently in this same way. This, I believe, is what you're asking how to do.
To illustrate, here's a screenshot showing just what this looks like, here with three projects being managed in a single window/main project:
Per the "Project: if-lab" section heading in the above screenshot, PyCharm/IntelliJ seems to have a notion that one of the projects is the primary project. You can see this in the Preferences pane, where the per-project settings are listed under a heading like "Project: xxx", where "xxx" is the name of the primary project.
I'm not sure just how the notion of one project being the primary comes into play.
Here is a page from the PyCharm documentation that explains some of this:
https://www.jetbrains.com/help/pycharm/opening-multiple-projects.html
The following section of that page explains how sub-projects interact with the primary project:
A newly opened project shares the same window as the already opened
one. The project that has already been opened, is considered the
primary project, and is always shown first in the Project tool window.
All the other projects are added to the primary project.
You can import classes and methods from dependent projects. Use the
Dependencies project settings to configure this behavior.
Some settings (such as Django, Buildout, Google App Engine, template
languages, Python interpreters, content roots) can be configured
separately for each project.
You can also configure different execution environments independent of the project's environment by creating multiple Run/Debug Configurations. These settings control what happens at execution time, but do not affect such things as syntax checking and highlighting, code completion, etc.
I've already accepted the very detailed answer by #Steve, and found it very useful to get me on the right track. But for my specific IntelliJ version(2020.1.2 on MacOS) I had to set it up a bit differently, so am including what I did as an alternate answer:
Note, that for my version of IntelliJ and this approach, the subdirectory to serve as a python root does NOT need to be a project itself, as is the case in Steve's answer.
Step 1) Set up a virtualenv for the subdirectory of your project which is to serve as the root your python code. I used python poetry, whatever method you use, note the path of the virualenv's python executable as you will need to enter it in IntelliJ later.
Step 2) Open File -> Project Structure. A window pops up (eventually took 30 seconds or so for me).
Step 3) On the panel at the left of the Project Structure window, select "Modules"
Step 4) A the top of the second column from the left is a + - and copy icon. Click the + icon. A drop down appears and you should select "Import Module", causing another pop up to appear.
Step 5) In the Pop Up, navigate to the subdirectory of your project that is to serve as the root directory of your python script and select it with the Open button at bottom right. The pop up window disappears and after a few seconds an "Import Module" popup window appears.
Step 6) In the Import Module window select "Create module from existing sources" then click the Next button and follow the Wizard like steps, which will give you the chance to specify the virtualenv path you setup in step 1.
Step 7) Click Finish for the Import Module window, and you should be set up.
This issue has come up with previous versions of PyCharm (see this SO post and this one), but it manifests somewhat differently in 4.5.
I am trying to add another library to the Python path of my current project. This is an internal library and consists of a bunch of .py files in a different directory from the current project. I carry out the following steps:
Go to File -> Settings -> Project: summary -> Project Interpreter
Click on the gear icon near the top right corner of the screen that appears in the dialog
Select More... from the context menu that pops up
Click on the interpreter I am using
Click on the last of the 4 icons to the right of that, the thing with a folder and arrows, with tooltip "Show paths for the selected interpreter"
Push + in the resulting popup
Use the file dialog to add the path of the library
Having done this, the result is:
Good:
Running the current project code from a Run Configuration works; that is, the external library is picked up in the PYTHONPATH
The added path does not immediately disappear from the interpreter path dialog, as it was doing in 4.0 (see comment to this answer in one of the SO posts mentioned above).
Bad:
Indexing of the new library fails, and all references to the external library are marked as unresolved references in the editor
I have even tried File -> Invalidate Caches / Restart... and pressed the Invalidate and Restart button that appears. After sitting and waiting for indexing to finish, I get the same result. I have been very careful with setting the right path, and it seems to be correct, given that running the code actually works.
Does anyone know of a workaround for this issue, short of adding the external code as a content root?
I ran into a very similar issue. I am working on an OpenStack component, and all third-party libraries were getting marked as unresolved references. It turned out to be because the .tox directory is automatically excluded by PyCharm, which prevents any virtual environments in that directory from getting indexed properly.
To fix this, I went to the Editor > File Types dialog of the Preferences menu, and removed the .tox folder from the Ignore files and folders option.
Checked w/ JetBrains support, they confirmed that the only ways to add external libraries to a PyCharm project are:
Add the library as a Content Root
OR
Open it as separate project in the same window and attach it to your current project
Not the cleanest approaches, as they both basically mean adding the other library's actual code to your project. But they are the only ones at this point.
I'm brand new to Eclipse (learning Python). I'm really confused about the terminology within Eclipse. I had previously created a "hello world" project and exited Eclipse. I've restarted Eclipse, but how do I list all of the projects in the current workspace? Is there a way to do that? If not how do I open a project? I tried using "Import" but it said the project was already in the workspace. What ever happened to say an option to "Open Project..."? This seems way overly complicated. I guess other questions I have are:
How do you determine the currently set "workspace"?
How do you see what workspaces are available?
The projects for the current workspace are shown in the "Package Explorer" view, which displays them as in a "Windows Explorer" fashion. Using this view you can open/close and manage your projects for a given workspace. If you currently don't have Package Explorer open, you can go to Window->Show View->Package Explorer. If package explorer is not an option there just select "Other..." and look under General.
Note that projects are not shared across workspaces, so if you create a new workspace or switch to a different one you won't see the other one's projects.
I can use the shared editing feature of ECF with Java fine perfectly fine. When I try to do it with Python files it also works, but there is no syntax highlighting.
I installed PyDev to get syntax highlighting, but then the context menu does not have the "share editor" option. I removed PyDev and the option came back. I installed Dynamic Languages Toolkit in hopes that its Python syntax highlighting was compatible and I got the same effect (context menu lacks the "share editor" option).
Is there a way to have a shared editing session with Python files and syntax highlighting?
You have to add the context menu into the PyDev editor manually.
You can do this by setting up a plugin with the following inplugin.xml:
<plugin>
<extension point="org.eclipse.ui.menus">
<menuContribution
locationURI="popup:org.python.pydev.editor.PythonEditor.EditorContext">
<dynamic
class="org.eclipse.ecf.docshare.menu.DocShareRosterMenuContributionItem"
id="com.foo.MyVeryOwnEditorContextID.dynamic1">
</dynamic>
</menuContribution>
</extension>
</plugin>
Here, org.python.pydev.editor.PythonEditor.EditorContext is the context id of the PyDev Editor.
If you want to add the context menu item to another editor you'll have to change this id. It can be found by pressing Shift-Alt-F1 while using in editor you want to add it to.
com.foo.MyVeryOwnEditorContextID.dynamic1 simply has to be a unique id of your choice.
You then have to put the plugin .jar file into your plugins folder in the eclipse directory.
There's a Github project called ECF4PyDev which provides a module to perform map the ECF menu commands into PyDev. The project also includes the necessary files in order for direct installation, which makes it easy to use with the Eclipse software installer.
Installation
in Eclipse, go to "Help" -> "Install New Softare..." then click the "Add" button. Add the following information:
Name
ECF for PyDev
Location
http://gilberterik.github.com/ECF4PyDev
The UI should then show a checkbox for ECFPyDev. Select it, then hit next. Continue to follow the wizard until the installation is complete. It may take a moment to finish the install - be patient. After installation, you should be prompted to restart Eclipse.