Such as:
It can not show tipMember.objects when I type Member.o.(Member is a django model)
And same with python build-in function, like for,filter, map and so on.
This feature worked yesterday, I don't know why it broken now.
I have tried Invalidate Caches / Restart, do not work.
UPDATE
Maybe I know what is the problem.
I have a big folder name ALL project, it is my project. and project A under ALL project.
I accidentally mark project A excluded. And I use File -> Open .. to add it back.
It seems pycharm create .idea folder under project A, it means pycharm treat project A as a project.I have to set Project Interpreter for project A in order to get auto-completion back.
I don't want pycharm treat project A as a project. I want it treat project A as a folder, then it would use the Project Interpreter of ALL project.
Ok, I find that Project Structure dialog in File | Settings | Project Structure . Adding the folder back make every thing fine.
Have you set project interpreter correctly, i also had this problem when i started using pycharm, it can be also because of your editor settings file>editor>code-completion.
Related
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.
I was handed a project which uses Django and Docker, but when I run Django tests Pycharm always seems to have problem finding the users application. Other people in the project have it running without problems but even though we tried to copy their settings, it wouldn't work. I also downgraded to their exact Pycharm version without success. What could be wrong?
I have Docker desktop running without any problem. It's able to create containers and all that. I've also included it in Pycharm with success.
I've also created an interpreter through Docker-compose with a valid .yml file. This file is my colleagues.
I've of course added it as my project interpreter.
I've set up a Django test configuration with appropriate interpreter and with an empty target field so that all applications in INSTALLED_APPS are run, as per documentation.
Still, the module 'users' cannot be found. Passing in DJANGO_SETTINGS_MODULE=config.settings.local to the test configuration yields the same error.
However, when I run from the terminal, all works as expected.
What might be the problem here?
I was using the modern django setup (generated from cookiecutter-django) which Pycharm seems to have trouble with. By right-clicking the folder and choosing "Mark directory as" and marking my project directory as "Sources Root" (i.e. the project/project folder), Pycharm was able to run it properly.
Did you try unchecking options related to PYTHONPATH in your run configuration?
It may override your modules path and cause such mess with finding them.
This's probably quite off-topic but maybe someone else share my experience... when I started coding KiCAD plugins and learning Python I decided to use VSCode (with Microsoft Python extension) because I already use it for a number of other things and works great.
I have two main issues mostly bound to Python extension itself other than VSCode:
VSCode try to use python 3.7 binary (I installed it on my
machine and I need it) instead kicad/python 2 (it's installed on a different location);
even if I setup VSCode to look for additional packages with a specific configuration file (settings.json):
"python.autoComplete.extraPaths": ["C:/Program Files/KiCad/lib/python2.7/site-packages"]
VSCode refuse to investigate pcbnew.py (located in that folder) and thus every Intellisense like function (inspection etc) doesn't work.
How can I fix that? ... I'm more interested in fixing the second issue other than the first.
To correctly enable per project configuration of VSCode / Python open folder and create a workspace configuration for the project itself (i.e. create a .vscode folder inside project folder and store a settings.json file inside it with you custom configuration). In my specific case I needed to specifiy a custom location for an older Python binary trough python.pythonPath directive.
Pycharm doesn't recognize the packages of my project's modules.
I noticed there are already quite some questions on this, but I tried all the given solutions and nothing works.
I tried:
- Mark directory as source root & checking Add sources root to pythonpath
- Opening a different project and then reopening the original one to make pycharm reindex the packages
Any suggestions?
I went over the following questions
PyCharm does not recognize modules installed in development mode
Pycharm not recognizing packages even when __init__.py exits
Just in case people got here with a similar trouble as I am. I had all files __init__.py correctly but pycharm didn't recognize those package properly. Finally, this following way worked for me:
In pycharm,
1. right click on a base folder of your code
2. Choose "make Directory as"
3. Choose "Sources Root"
Hope this helps.
Ok it is quite funny to answer my own question, but I understood that is the encouraged way to go if you actually found the answer.
So what was causing this problem was that __init__.py was listed as a text file in Pycharm settings.
If you go to Settings | File Types | Select Text you see a list of file names/extensions that Pycharm recognizes as text.
I think this happened because I created a file named __init__ without file extension, and later changed it to __init__.py
Removing it from there fixed the issue.
I would suggest the following
Close pycharm
Delete the .idea folder
Open the project as new project
Make sure you have the __init__.py files where they belong (each package needs one)
It should not be necessary in this case to add anything to the pythonpath or source root manually. This is only necessary if you work on two projects with are disconnected from each other and you want them to be able to import from each other.
In the latest release of Pycharm, setting the project folder as "content root" fixes your problem.
Go to Preferences
Go to Project -> Project Structure
Add content root with your project directory path
If I'm closing a project and then just delete the project folder, after PyCharm restarts an empty project folder is created again.
Just follow these steps in order. They assume you currently have the project open in a PyCharm window:
Close your project by clicking on File -> Close Project
Locate your project in the PyCharm file directory
Delete your project's directory
I agree that PyCharm's handling of what should be a very simple procedure is crappy. Maybe this will be improved in the future?
If you want to remove the project from the recent projects list, just highlight the project with your mouse and hit the del key.
This is for PyCharm 2019.1, but I can bet this will work in previous versions.
I am assuming you are in a Unix based operating system (macOs or any Linux distribution). I am also assuming you have currently opened the project you want to remove.
Close the project by going to File → Close Project:
Remove the project from Pycharm's Welcome Window:
Locate your project and delete it, you can use several alternatives, but I encourage you to use the following
$ rm -rf /path/to/your/project/directory
The previous command will work in macOS and Linux. In Windows, you can delete it manually by locating the projects directory using File Explorer.
That's it, the project has been completely deleted!
click the project you want to remove.
menu bar Edit-> Remove from Project View.
Version 2017.2.1
Press Alt+1 to bring the project pane, and make sure you're in
Project view (not Project Files view).
Select the desired project, and choose "Delete from project
view" from the context menu (right click). You can also use Delete
key.
There is a difference between PyCharm projects and the list of recently opened projects (File → Open recent...):
The PyCharm project is simply an arbitrary folder1 with the appropriate .idea subfolder in it.
The list of recently opened projects is simply the list of paths to some of such folders.
PyCharm does not keep the list of all projects, so you may safely delete a project folder (or its .idea subfolder) from your file system.
But if you have a bad luck, the path to your project directory is already listed in the list of recently opened projects, and if you try opening it with File → Open recent..., then
in older version of PyCharm, the deleted folder is re-created (as a new folder with only the .idea subfolder in it),
in newer versions of PyCharm you get the prompt similar as
The path C:\Users\you\PycharmProjects\deleted_project does not exist.
If it is on a removable or network drive, please make sure that the drive is
connected.
with buttons "OK" and "Remove From List", so you may simply remove the deleted folder from the list,
in all version of PyCharm, if you deleted only the .idea subfolder, it is silently re-created (but all your project settings are lost, of course).
To prevent from the uncomfortable consequence of the 1st possibility of using the File → Open recent... to re-create already deleted project, follow e.g. the first two instructions in the Simin Jie's answer.
1 generally a subfolder of the PyCharmProjects folder in your user profile directory (e.g. if you created it with File → New Project... and accepted the offered default path).
Works for Windows and MacOS.
File -- Open Recent -- Manage Projects
Cliek X to delete from Recent Projects
Delete local directory
According to https://www.youtube.com/watch?v=ksbmc0coO4k
In PyCharm 2018 I finally had to resort to deleting .idea folder and the project went away.
Highlight the project with your mouse and hit the del key, which works for me.
In 2021 maybe another way to do it. My problem was in project with user directory (root was /Users) that contains too many not Python files, and it triggers some problems with Git and file index.
What I did:
show hidden files (Cmd + Shift + .),
find .idea directories,
delete all .idea directories.
open PyCharm and add project from correct directory.
That's it.
I had the same issue. My solution was:
Close project.
Rename the folder you want to dissapear
Open pycharm project. A dialog will be shown asking if you want Pycharm remove the folder. Answer: yes.
That is enough.
In version 2017.2.1
File → Close Project
You will be taken to the start-up window, where you can see the projects you've created on the left. You can then delete a project by clicking the cross sign ('x') following the project name.