Pycharm can't find Django app 'users' when running tests - python

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.

Related

How to enable PyCharm code inspection for packages

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.

pycharm and subprocess - what works in console doesn't work in Pycharm

Pycharm's interpreter seems to have stopped understanding some of my console commands. It keeps recognizing default shell commands but doesn't recognize installed utilities.
For example, subprocess module understands touch command but doesn't understand heroku command.
The funny thing is, when I enter the same string into the console, with the same interpreter (from the same virtualenv), everything works fine.
A visual example:
It stopped working a couple days ago, and before that everything had worked fine.
I thought I had messed up some of my env vars, but opened an old project I hadn't touched for a month, and saw that the same subprocess commands stopped working there too.
What could be the problem?
UPDATE
Ok, I got this thing to work.
The values of os.environ['PATH'] were different in console and in Pycharm. After I added the correct PATH to the Pycharm configuration env vars, everything started working again.
Now the question is, how do I avoid going through each configuration in each and every of my projects and adding this new PATH everywhere? Is there a way to do this globally and repair this one only setting that's been broken?
I see you figured out how to configure PyCharm's project PATH.
As for how to not have to do this for every project new project you start, you just have to update your default project configuration.
From Accessing Default Settings:
PyCharm helps define settings of a default project. These settings
are used as defaults every time you create a new project.
To access default project settings
On the main menu, choose File | Default Settings
Define the desired settings in the Settings dialog box that opens.
Note: updates to the default project configurations only apply to future new projects, any existing project configuration needs to be updated manually.

/_ah/admin (and /_ah/*) doesn't exist in Python GAE with virtualenv

I used to use vagrant to run my GAE Python apps, but I wanted to tried with virtualenv.
Everything worked okay, but I can't access anything in /_ah/* - I would only need /_ah/admin and also /_ah/img, where uploaded images from the admin panel are located.
I checked my app.yaml and it has everything: the admin_redirect builtin is okay, and I also tried to include the admin_redirect .py manually.
This is the file, just in case:
http://pastebin.com/eV9yTegf
(I tried with threadsafe yes and no, also).
Can anybody help? I am totally stuck, I tried everything and I don't know what to do next.
If you are running the latest version (1.8.0+) then the admin console is actually running in a different port. By default is running in http://localhost:8000/ but you can change that by running the dev_appserver.py with the an option --admin_port.

PyDev Debugging

My interpreter is the python 2.6 interpreter that comes with cygwin.
I have a pydev project that contains a linked folder.
In the folder, due to outside constraints, I have two sub-folders, one with a bunch of scripts I develop, and one which serves as the run directory for all my run configurations.
When I run the project (not debug) everything works fine.
However, when I choose to debug the project, my custom modules aren't found, and the import fails.
I tried adding my scripts folder to PYTHONPATH, but that didn't help, and when I printed sys.path It contained weird stuff, all of the form:
<path to run directory>/<path to entry in PYTHONPATH>
I can't make heads or tails out of it.
I'll appreciate any help.
Unfortunately, that's a known issue. PyDev does not support Cygwin for debugging. The primary reason is that the paths that Python reports don't match the paths you configure in windows, so, a translation step would be needed for each path (even some other areas such as code-completion or code-analysis could have problems).
You can probably do this translation yourself at eclipse/plugins/org.python.pydev_x.x.x/pysrc/pydevd_file_utils.py (instructions on the file), but note that this may be more work than it's worth (the recommended approach is using a native Python install on Windows instead of through cygwin) -- or if you need an interpreter on Linux, develop on Linux :)
Thanks, you made my day, its actually very easy,
you have to change the PATHS_FROM_ECLIPSE_TO_PYTHON variable inside pydevd_file_utils.py as,
PATHS_FROM_ECLIPSE_TO_PYTHON = [
(r'C:\Users\usernam\workspace-cpp\python-proj\src',
r'/cygdrive/c/Users/usernam/workspace-cpp/python-proj/src')
]
But this needs to be changed for all your own python source files you desire to debug
I am happy to announce a new release of ePyUnit, which solves the load-path issue of 'pydevd.py'. This works from within Eclipse/PyDev as well as from an arbitrary process started from the command line.
ePyUnit now includes the automation of remote debugging with PyDev and Eclipse by 'pydevd.py'. This works seamlessly for the 'subprocess' call as well as independently started command line processes.
See:
https://pypi.python.org/pypi/epyunit
https://pythonhosted.org/epyunit/
For basics of remote debugging:
http://www.pydev.org/manual_adv_remote_debugger.html
Also enhanced unittest integration into PyUnit.
Comments and fixes are welcome.
Have fun...

Why is django giving error: no module named django.core?

I get the error in question when I attempt to create a project. I followed the instructions found at how to install python an django in windows vista.
Also make sure that you have permission to access all of django's files. I've seen these kinds of errors happen because of permissions issues before.
EDIT: I haven't tried it out, but there's a link on that page to Instant Django, which looks like a pretty easy to set up.
You can get around this problem by providing the full path to your django-admin.py file
python c:\python25\scripts\django-admin.py startproject mysite
Most likely you don't have Django on your Python path. To test, quickly fire up Python and run:
>>> import django
If that fails, it's just a matter of getting Django onto your Python path. Either you set the environment variable, or you move django into your python2x/Lib/site-packages directory. If it does work, try importing core. If that fails there, then something is probably wrong with your Django install.
From your command line (cmd) run "ftype Python.File" and make sure that your .py files are being executed by the correct version/installation of Python.
It's possible another application has surreptitiously changed this under the hood.

Categories

Resources