We are keen to use PyDev for our edX customizatoin and we want to configure edX code on it. Do you know of any documentation which talks about how to configure PyDev for edX code? Basically, I have imported all the projects of edX into PyDev but I am stuck at the point of building the projects as I am not aware of the configurations required to be done and there are lot of dependancies between various projects. Any help would be appreciated. Thanks & Regards,
Abhijeet Mote
I happen to know where to find the directions for configuring Eclipse.
You can find the details at the attachment of this post.
Edit: Update based on the configuration from the link
Create MITx python environment
Go to Windows>Preferences>PyDev>Interpreter - Python (Ubuntu) or Eclipse>Preferences>PyDev>Interpreter - Python (Mac)
Set up (or create new) location, pointing to ~/mitx_all/python/bin/python. You may need to spell out the home path. You may get a warning saying that source code is not found.
(If necessary, add /usr/bin/python2.7 to list of included paths for interpreter. That might provide some of the missing source code.)
Create MITx project
Do File>New>Other, select PyDev/PyDev Django Project
Enter "mitx" or similar as the project name and point to mitx_all/mitx location
In project properties (right click the project in left panel), set PyDev - PYTHONPATH, Source Folders to:
the root dir /mitx
/mitx/common/lib/xmodule
/mitx/cms
/mitx/cms/djangoapps
/mitx/lms
/mitx/lms/djangoapps
/mitx/lms/lib
/mitx/common/djangoapps
/mitx/common/lib
Create a manage.py file to use that's within the project hierarchy (instead of django_admin.py, which is over in mitx_all/python/bin). For example, put the following in ~/mitx_all/mitx/manage.py:
#!/home/<username>/mitx_all/python/bin/python
from django.core import management
if __name__ == "__main__":
management.execute_from_command_line()
Open Debug Configurations dialog. (Either right-click on project -> Debug as -> Debug Configurations or menu Run -> Debug Configurations to bring up configuration dialog.)
In dialog, right-click on PyDev Django -> New (New is the icon above the left nav).
On main tab, set name: pick a name to indicate what Django config you're using (e.g. LMS dev with runserver).
Project should be MITx (or whatever you called it)
For main module, browse to location of manage.py created above.
On Arguments tab, put program arguments. For example, to run the LMS, put "runserver --noreload --settings=lms.envs.dev --pythonpath=. 8000".
On Interpreter tab, select the MITx interpreter [which is in the drop down] (the one that uses mitx_all/python). This may be the same as your default interpreter, depending on your global interpreter settings.
In Environment tab, set DJANGO_SETTINGS_MODULE to point to the desired setting file (e.g. lms.envs.dev). If you aren't running with activate and such, then PATH may also need to be set (or augmented)
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.
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.
Rather frustratingly, every time I load up an existing project or create a new one - it complains there is no interpreter selected and I have to provide the path to it.
There is nothing unusual about my python installation, it's sat in C:/Python27/ as you would expect. It always used to work, but the last few weeks something has changed.
I'm running Win7. PATH system variable points to C:/Python27/ as it ought to.
If I crack open commandline, the python command opens as it ought to.
Any ideas?
There is no Default Settings any more, It's called Preferences for New Projects in the newer versions of PyCharm (my version is 2018.3.3).
For that, go to :
File > Preferences for New Projects > Project Interpreter
Setting the IDE default interpreter fixed the problem, as Vadim mentioned. Found instructions on how to do that here.
File | Default Settings | Project Interpreter.
This configuration sets the default interpreter for the new projects,
note the Default Settings menu, it's not the same as File | Settings
which sets options for the current project.
Not entirely sure why the default was unset, but at least now I can set it back again. The project default setting was being forgotten as well which is curious, but a problem for another day.
You can easily do it by going to File > Setting for New Projects > Project Interpreter:
On Mac: File > Preferences for New Projects.
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 want to use Intellij Idea within my existing python django project which was built within a virtual environment in ubuntu. How do I configure Intellij Idea to use the libraries of the virtual environment?
For PyCharm 2018
As per documentation from Pycharm:
In the Project Interpreter page, click and select Add.
In the left-hand pane of the Add Python Interpreter dialog box, select Virtualenv Environment. The following actions depend on whether
the virtual environment existed before.
If Existing environment is selected:
Specify the required interpreter: use the drop-down list, or click Select an interpreter and find one in your file system.
Select the check-box Make available to all projects, if needed.
Click OK to complete the task.
For Pycharm 2016 and later
To add an existing virtual environment to the list of available interpreters
In the Project Interpreter page, click .
In the drop-down list, choose Add local.
In the Select Python Interpreter dialog box that opens, choose the desired Python executable, located inside the virtual environment folder, and click OK.
Go to this link for more information.
For Older versions:
Well I solved the above problem. I have added virtualenv folder's python to project sdk. The virtualenv directory's python( for example venv/bin/python2.7) needs to be added to Intellij Idea project path. Example: need to go to file>project structure (intellij Idea)
press new in Project SDK, and add new path to virtualenv's python directory like this:
Go to Modules>Dependencies and set your module sdk to Python SDK which is marked on this picture:
Click on Django (option marked in next the image) and set Django project root, Settings,Manage Script like this:
Now press ok and final look of the Project settings:
Now need to run the project.
The above answer is based on older version of IntelliJ. For new, look here: https://www.jetbrains.com/help/pycharm/2016.1/adding-existing-virtual-environment.html