I recently created a Python package which I use in most of my projects so I moved it to my user-site directory (python -m site --user-site). Everything works perfectly now except for the fact that PyCharm has disabled code inspection for it.
Is there any way for me to enable code inspection without moving the project back to a different directory?
It turns out it was because I didn't have an interpreter set for my project (and not that it was placed in a site-packages directory). I assumed that it did due to the fact that PyCharm didn't have it's usual "no interpreter configured for this project" alert. Finally figured it out when I went poking in the settings.
Related
Problem Statement
My PyCharm project does not recognize any Virtualenv project interpreter, including ones it successfully creates.
Steps Taken to Produce Error
I opened PyCharm to the Welcome to PyCharm window.
I clicked Get from Version Control. I cloned a private repo from my GitHub into my local system. I confirmed that all files from the repo were present.
I opened the Add Python Interpreter window via File -> Settings -> Project: myProject -> Project Interpreter -> (gear button) -> "Add...".
I selected the Virtualenv Environment option and the New environment radio button. I confirmed that the target Location (...\myProject\venv) did not yet exist. I selected Python 3.7 as my base interpreter, an installation which I have used without issue in other projects. I left both Inherit global site-packages and Make available to all projects unchecked.
PyCharm successfully created the Virtualenv. I confirmed this in both PyCharm's Project tab and Windows Explorer. Double-clicking ...\myProject\venv\Scripts\python.exe launched a Python 3.7 shell as expected.
However, PyCharm's infobar at the bottom of the main window said <No interpreter>. The Project Interpreter settings menu also said <No interpreter>, and upon expanding the interpreter list dropdown, the interpreter which PyCharm had just successfully created for myProject was not listed.
Note
After taking the above steps, the newly-created Virtualenv is listed as an option under the Existing Interpreter radio button. However, selecting this option does nothing; the Project Interpreter window still says <No interpreter>.
Failed Remedies
Closing and Reopening PyCharm.
Choosing the Existing Interpreter radio button and targeting myProject\venv\Scripts\python.exe.
Choosing the Existing Interpreter radio button and targeting the python.exe in a different project's Virtualenv.
Restarting my computer then Existing Interpreter -> myProject\venv\Scripts\python.exe.
Creating a second Virtualenv (myProject\venv-2).
Deleting all existing Virtualenvs, then creating a new one in myProject\venv.
Leads
Creating a new, separate project (myProject_2) using the exact same steps as above does NOT replicate the error; a new Virtualenv is successfully created and recognized. This error is unique to myProject.
Regardless, I'm going to leave this question up. I want to understand what's going wrong here.
[Project Directory Structure]
myProject
assets
css
images
js
MyProject
courses
migrations
templates
courses
templatetags
templates
users
migrations
templates
users
templatetags
venv
[Info]
Microsoft Windows 10 Pro
PyCharm 2019.3.3
Python 3.7.7
The solution suggested in this answer to a related question—where the error message "Please specify a different SDK name" is being raised—about PyCharm interpreters may be what you are looking for.
I also had an issue with interpreters not loading, and it turned out to be an underlying conflict, which PyCharm was not giving me any helpful error messages about. The issue wasn't resolved until I deleted the jdk.table.xml file, which for me (on Mac OS) was located here: ~/Library/Application Support/JetBrains/PyCharm2022.2/options.
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.
I am developing a robot using the ros framework. As ide, I use PyCharm. But I can’t import ros into it. On the ros site there is the article about ide http://wiki.ros.org/IDEs. There is information about using ros with pycharm. I have to modify the .desktop file, but I installed PyCharm using a snap from the software center. Where can I find the .desktop file for snap applications? Can there be another method to import ros into PyCharm?
Edit:
#hug Yes, I launched this command here is the result
/snap/pycharm-community/103/meta/gui/pycharm-community.desktop
/snap/pycharm-community/103/snap/gui/pycharm-community.desktop
/var/lib/snapd/desktop/applications/pycharm-community_pycharm-community.desktop
/var/tmp/pycharm-community.desktop.swp
I think that the .swp file has remained since the last reinstallation of PyCharm. I reinstalled when I tried to do it myself and realized that I had broken the program.
If you want to use from the auto-suggestion with ROS packages in Pycharm IDE, you could do the following instructions:
File > Settings (or Ctrl+Alt+s as shortcut)> Project: > Project interpreter.
In the project interpreter dropdown list, you can specify ROS Python interpreter by selecting the appropriate from the list.
[NOTE]:
You could add a virtual environment with the above instructions, then you should add ROS distpackages (roslib) on it with this instruction.
ROS distpackages path that you need: /opt/ros/kinetic/lib/python2.7/distpackages
Follow these video instructions for setting up pycharm with ROS.
https://www.youtube.com/watch?v=lTew9mbXrAs
Debugging, code completion, imports, etc all behave correctly. You can do all your python ROS development entirely in pycharm.
In summary:
Create a virtual environment virtualenv venv --system-site-packages
Source your virtualenv and your ROS workspace and launch pycharm from this (sourced) terminal. (enable Shell Scripts in the JetBrains Toolbox to allow command-line pycharm)
Under the project structure you will "Add Content Root":
Keep [ros_workspace]/src (which should already be there). Mark all the the src folders containing python code as "Sources".
add /opt/ros/noetic/lib/python3/dist-packages
add [ros_workspace]/devel/lib/python3/dist-packages. Exclude any packages in [ros_workspace]/devel/lib/python3/dist-packages that contain source code (e.g. are not just message packages). If you have packages that contain both source and messages, you will need to separate these for pycharm to resolve imports correctly in the editor
More details and explanation in the video
If anyone else is struggling with getting PyCharm intellisense and autocomplete to work with your own ros python packages, this answer was very illuminating.
Basically PyCharm does not dynamically interpret the devel/ space __init__.py for your packages, so at runtime the packages are available, but no intellisense in PyCharm. Changing the Project Structure settings to add your <package>/src as a Source folder solved the issue for me. Bit of a pain, but hey, intellisense is back!
My PyCharm 5.0.1 installation does not resolve references to any builtin modules or methods:
As you can see, I have installed python over cygwin.
I already tried:
reinstalling / updating the python installation (from 2.7.9 to 2.7.10)
reinstalling pycharm
adding a interpreter path to the python-skeletons in the pycharm installation directory (this was immediately removed by the ide when saving the settings, implying, that it already is embedded)
removing the interpreter (this removes the warnings, but also the code completion, and import asdflkjasd is valid as well)
adding various paths like /lib/python2.7/site-packages/ to the interpreter packages option
None of these improved the situation.
How can I fix this without installation outside of cygwin alltogether?
This is an update with a much better solution than my previous answer (which I completely missed that OP was asking for a solution that didn't require exactly what I suggested).
Like Carl commented above, updating python-skeletons is actually the way to go, however, if you're using Cygwin, the interpreter paths are a little wonky, and PyCharm won't always automatically add the right paths. For me, PyCharm handled it just fine in version 4.5.4, but not 5.0.4.
You'll find the python builtins in your Pycharm config directory, probably at:
C:\Users\[USERNAME]\.PyCharm50\system\python_stubs\-[RANDOM_STRING_OF_NUMBERS]
Just manually add this path (or paths) to your interpreter and it should resolve your problem. You can do the same for your site-packages folder if that's currently polluting your project structure space.
To get to the right menu:
Click File -> Settings
Navigate to Project -> Project Interpreter
Click the gear on the top right and click "More"
Select your interpreter and click the "Show paths" button on the right
Instead of clicking refresh, as many other posts suggest, click the "Add" button on the right and add your paths
There's a handy screenshot uploaded by r---------k on the updating python-skeletons post that if that helps you.
Try installing the Python package for Windows from
http://www.python.org/download/windows and point PyCharm to that
interpreter instead.
Settings -> Project -> Project Interpreter -> Gear -> Add Local
You may also need to install PyCharm's Python packaging tools (you
should see a link on the bottom of the Project Interpreter page if it
isn't installed already).
While this may not be a perfect solution depending on your workflow
because PyCharm will no longer be using Cygwin's python interpreter,
but this at least got rid of those pesky squiggly red underlines for
me.
I use Windows 10 x64, Python 3.5.1 and PyCharm Community Edition 2016.1.4
I have the same problem and sovled it by runnig PyCharm in admin mode (it is required only once).
I'm doing my VERY first project using python/django/eclipse/pydev following this guide
http://docs.djangoproject.com/en/dev/intro/tutorial01/
My only addition is the use of Eclipse/pydev.
I'm getting many errors related to "Unresolved imports". I can remove the errors using "remove error markers" and my site runs perfect (I can browse it) but I want to get rid definitively of this problem since errors pop up again after I removed them.
Any ideas?
EDIT
Using Ubuntu 9.1
Check your pythonpath. You need to include the parent directory of django, usually Lib/site-packages.
I'm on Mac OS X, but all I had to do was to add:
/Library/Python/2.6/site-packages
to my System PYTHONPATH (Found in: Preferences > Pydev > Interpreter - Python)
The equivalent for Ubuntu 10.04 would be:
/usr/lib/pymodules/python2.6
I'm guessing that the equivalent for Ubuntu 9.x could be:
/usr/lib/python2.6/site-packages
If it isn't and you're tired of looking, just upgrade to Ubuntu 10.04 and you should be fine.
I was able to get rid of the import errors executing this cmd
sudo ln -s /usr/lib/pymodules/ /usr/lib/python2.6/pymodules
I was lucky, testing different things I could resolve it but I'm not sure why I have to do this and how I could avoid doing it.
"Unresolved imports" occur when Eclipse/Pydev does not know what you want to import. Check your Pydev settings in the Eclipse preferences > Interpreter Python. Your site-packages folder and things you want to import should be there in the Pythonpath.
Also see http://pydev.org/manual_101_interpreter.html
Even if Lib/site-packages is added to the PYTHONPATH, this problem may happen when using modules from egg packages installed using easy_install. The problem with those, and that might actually depend on the easy_install version, is that by default they don't get installed directly inside Lib/site-packages but rather under a folder containing the full package name and having the .egg suffix. For example: Lib/site-packages/django_celery-3.0.23-py2.7.egg
Each module coming from packages installed as above needs an individual entry in PYTHONPATH. If the packages are installed after PyDev has been installed on the system, the system PYTHONPATH needs to be updated in PyDev. That is done automatically by going to Window -> Preferences -> PyDev -> Select your intepreter -> in the python interpreters panel remove and re-add your current python interpreter (usually, this should be the python executable from the system). Then a PyDev restart (File -> Restart) should solve the "Unresolved import" errors.
If you are facing problem of unused imports then I must say use Eclipse as a IDE as it is providing functionality to remove unused imports by pressing keys ctr+shift+O. Or In Eclipse there is plugin also available which is doing the same thing automatically when you save your code.You can get that plugin from eclipse plugin site easily and free of cost.
In my case of the modules were dependent on setuptools-14.3.1 , which was causing all these problems. After installation of setuptools-14.3.1 rest of the modules automatically resolved.
I was having a single import error when working in PyDEV in eclipse.
I was importing it like
from xyz_module import abc
So I clicked "Ctl + 1" and "select Unresolved import error" in eclipse and it created a class
file in a python file.
It turned out that I had created an application called "xyz_module" and a "xyz_module.py" file (with the same name that is) and this was causing an import error. I changed the python file to a new name and this resolved the error.
I had the same error and none of the answers worked for me as there was no PYTHONPATH options under Window -> Preferences -> PyDev -> Python.
Instead I added PYTHONPATH setting in the menu:
Project -> PyDev-PYTHONPATH -> External Libraries -> Add Source folder
I added the path of site-packages like
/home/Documents/hcx/venv/lib/python3.5/site-packages
Now PyDev stopped complaining.