IntelliJ 12 Python - Issues with manage.py Tasks - python

I'm currently looking for a nifty Python/Django IDE and came across PyCharm from JetBrains which I tested for about a week now and I'm quite impressed by this piece of software.
However, I've read that IntelliJ Ultimate with JetBrains own Python Plugin offers about the same Features as PyCharm itself, so I went ahead and gave it a try, but experienced some issues which I didn't have within PyCharms.
In IntelliJ, the built in Feature 'Tools > "Run manage.py Task..."' works with most (e.g. runserver, startapp, syncdb, ...), but not with all commands:
Almost all sql-related commands like "sql", "sqlall", "sqlclear", ... are shown as available commands, but raise a "No Applications" error message when entered.
In PyCharm those commands works fine.
Running the test suite via "test" opens a box where I have to choose the applications which I want to test. However, there is only one entry "[All Applications]" and running it causes several Exceptions to be thrown.
Adding some new Applications to the "settings.py" file has no effect on "Run manage.py Task..." whereas in PyCharm it adds new commands to it. I've tried this for example with "django.contrib.gis" to enable "ogrinspect"
All those issues lead to the assumption that IntelliJ somehow fails to recognize the installed django applications. Did I miss some configurations or settings in IntelliJ which are already set in PyCharm?
To further explain what I did exactly:
In IntelliJ I created a new project "Python Module" then enabled Django as desired technology.
In PyCharm I just created a new project of type "Django Project".
All following steps were exactly the same.

Okay, so apparently the culprit is the IntelliJ IDEA Project Creation Wizard.
If you create a new project within PyCharms and choose Django Project as desired Project type, it just works. You don't have to configure anything else.
To do this in IntelliJ IDEA, create a new Project, choose "Python Module" as type and check Django as technology. In the new project go to "File > Project Structure", navigate to "Facets", choose your Django Module on the right and set the "Settings:" option to point to the specific "settings.py" file.
After this configuration, everything should work as smooth as in PyCharms.
I consider this problem as a bug, as the Wizard creates the basic project, including a "settings.py" file, but doesn't add it in the project settings. Plus, you don't get any warning that such a strongly needed settings file is missing.

Related

How to fix: Pytest "Create Test" dialog box won't open in Pycharm

I'm trying to follow the tutorial on jetbrains (link: https://www.jetbrains.com/help/pycharm/pytest.html) about using pytest in pycharm so I can work on test driven development. I'm stuck at the part where I'm supposed to create a test for a specific function in the Car.py module (found here: https://www.jetbrains.com/help/pycharm/creating-and-running-your-first-python-project.html#) by hitting ctrl+shift+T and then clicking "Create new test...".
Screenshot of the step in the tutorial I'm stuck at.
When I click "Create new test..." nothing happens. The dialog box which is supposed to pop-up does not appear.
I've gone to Settings>Tools>Python Integrated Tools and changed Default test runner to pytest like I'm supposed to. I checked packages in the Project Interpreter and pytest version 5.3.5 is there which I just installed. I restarted pycharm for good measure. Does anyone know why the dialog box might not be appearing? I'm sure there is a more manual approach to making the test file but the built-in pycharm ability to do this quicker/easier is preferable.
Thanks for answering your own question, you have given me an idea for my solution.
For what reason so ever, I was not providing PyCharm a root directory for my project so it was not recognising my files.
I changed it under:
Preferences > Project:"your project name" > Project Structure
It was a silly mistake in my case. I was not opening the proper project folder. Instead I was opening parent folder.
My hierarchy was
E:\Projects\SampleProject
Instead of opening SampleProject in PyCharm, I was opening Projects directory whole.
I think PyCharm will only open this if it recognizes valid structure of the project.
Press Ctrl+Alt+S to open the Settings window, go to Project <project name> > Project Structure and mark your source folders as Sources (highlighted as blue in my version of PyCharm). Then you should be able to create tests for them.

What are Django configurations?

I'm setting up a Django project for the first time using Pycharm, and I'm trying to figure out what the configurations do.
I have looked online at the documentation, but it seems to be more focused towards people who already know what configurations do.
I'm assuming it is used to set up my localhost, however I'm unsure. Any help would be greatly appreciated!
In an informal way, we can define PyCharm configurations as a comfortable way to start a new process.
Suppose that you have a Python script called main.py. If you have to run it via command line you will type
python main.py
In the same way, PyCharm offers the possibility to run this script using configuration. It's sufficient create a new Python configuration and setup the script path (location of main.py) and the relative python interpreter.
In fact, can happen that some scripts must be run using a virtualenv or a specific enviroments. For this reason, at the creation of PyCharm configuration we need to specify also python interpreter.
Configurations are not used just to start python scripts, but it's possible to create different types.
As you pointed out in your question, it's possible to create configurations also for Django.
A typical usage in this case is to create a configuration to start the runserver.
But this is not all, because it's possible create configurations also for django commands, for migrations and also for Unit Test.
Pycharm configurations are useful because in this way, no need to setup every time all environment to start a process, but you need just to create configuration and save it. You can use it whenever you want.
Last but not least, using configurations allow you to debug your code easily.
Configurations can be started also in debug mode.
PyCharm documentation
When you run your code/project in PyCharm, maybe you need to specify some set of environment variables, the entrypoint is a particular script in your project, maybe there's some other script you always need to run first before you can run your project, or lots of other fiddly things that are a pain to type in every time.
The purpose of PyCharm "Run Configurations" is to let you save all these kind of things into a single method of running your project with a single click or shortcut.
Django Configurations are a type of Run Configurations with a few extra Django-specific config options thrown in. The default settings in the Run Configuration are sensible (running on localhost:8000), although you will need to make sure you specify the location of your Django Settings File.
How I config Run/Debug Configurations in Pycharm Community:
Add a Python Configuration
Script path: "path to manage.py"
Parameters: runserver "host":"port" "option like '--noreload', '--nothreading'"
Python interpreter: "path to venv"
Now you are able to run with Shift + F10
In order to pycharm general setting left-top File>Setting
screenshot..
enter image description here
Python Setting....
Open a project or import
After open or import you view project name option in rigth-top bar like this
enter image description here
on click you can view configuration option. click it and view this form for all python or other environment setting.
enter image description here

Configuring a debug environment in Eclipse

I am using Behave to write BDD tests. The problem I have is that I am unable to create debug environment for these tests. I have successfully created an external tool run environment but that is of little help when I want to use breakpoints and debug the code.
Anyone who uses Lettuce/Behave/Freshen/Cucumber and could let me know how is the debug environment setup?
Found a solution on the Eclipse help page : http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Ftasks%2Ftasks-exttools-running.htm
It is possible to debug python steps (*.py) files in Eclipse IDE.
Belove solution works for:
Windows 7
Behave framework from https://pythonhosted.org
Just make:
Copy behave-script.py to directory that are located .feature files. You can find this file in Python27\Scripts\
In Eclipse add new "Debug as...->Debug Configuration->Python Run"
In a project choose your project
In Main module choose behave-script.py
Hit run and set brakepoints
Although you didn't mention Morelia (another BDD tool for Python) I thing you could try it. It doesn't need any special setup to integrate if traditional unittests works for you. Morelia's documentation: https://morelia.readthedocs.org/en/latest/

eclipse: Run/Debug current file

In search of a Python debugger I stumbled upon Aptana, which is based on eclipse.
Often, I want to debug a single python script. However, Aptana won't let me run/debug the currently opened file directly.
Instead, it requires me to create a debug/run configuration for each file I would like to run/debug. Alternatively I could create a Python project in Aptana.
But: I don't want to. I just want to be able to run or debug the currently opened file. This way I would like to debug my scripts without being forced to create a project first (for each single script!).
Can it be that hard?
This is because Aptana/Eclipse doesn't "realize" that the file you opened should be debugged using the Python debugger as it's not associated with a Python project/perspective (there's a lot of environment setup when a project is created in Aptana/Eclipse).
The simplest solution, IMO, would be to create a simple sandbox Python project and just stick your files in there to run/debug. Aptana should then realize you're dealing with Python and start running the Python debugger without setup (that's my experience w/ PyDev in Eclipse, at any rate).
See: Run External Python Programs with Eclipse PyDev (note: you really need a project, but your file doesn't need to be in it).

Django (w PyCharm) & PYTHON PATH issue

I have purchased PyCharm and am trying to get things to work however I am encountering this issue..
Once I start a project everything works great...
Now if I want a standalone app.. let's say at /users/me/djangoApps I understand I have to add this directory to the python path.. I am trying to do so by creating a file sitecustomize.py at lib/python/2.6/site-packages/
However once I create an app and try to import it I keep getting non excistance errors (yes I have reloaded the python interpreter in pycharm)
I reckon I am adding my locations to the python path in the wrong way.. Also I might not have my project location setup correctly (currently /users/me/djangoProjects)
Thanks,
Novice django'r
In pycharm open the settings "cmd" + "," and then to "Project Structure" click on "Sources" to include any modules.
Don't add that file to your python site-packages, then your django project is gonna be included for all future projects down the road.
If you wanna debug, within PyCharm, click the Run tab up top and choose Edit configurations. Choose the project you are working with and make sure you add the directory where your manage.py and settings.pr file are to the "Working Directory". So I assume it might look something like this:
Working Directory: /users/me/djangoProjects/{Project Name}
If there is something else that you need to add to the Python Path, you can add it it by going to File-Settings-Python Interpreter and then add a new path in the bottom window (but once again this will be used by any project you run in PyCharm
But if you are not debugging in PyCharm and just wanna run the app, I find it easier to run it from the command line. I assume you are on Mac by your path, open the Terminal and go to the directory where your project is (same directory as the manage.py file) and type:
python manange.py runserver
If you want to give it a specific port add it to the end
python mange.py runserver 9000
This way you can edit your code in PyCharm and it will get reinterpreted when you save the file. If you are debugging in PyCharm, you need to stop the debugger and run it again to pull in your changes

Categories