Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 862
surfsim Avatar asked Feb 02 '11 19:02

surfsim


People also ask

Can I use PyCharm for Django?

PyCharm supports the latest Django versions. The corresponding Python versions depend on Django.

Which is better Django or PyCharm?

Django rates 4.5/5 stars with 136 reviews. By contrast, PyCharm rates 4.6/5 stars with 647 reviews. Each product's score is calculated with real-time data from verified user reviews, to help you make the best choice between these two options, and decide which one is best for your business needs.

Is PyCharm and Django same?

Django belongs to "Frameworks (Full Stack)" category of the tech stack, while PyCharm can be primarily classified under "Integrated Development Environment".

How do I import Django into PyCharm?

PyCharm is incredibly easy for Python development, especially for Django development. All you have to do is go to the navigation bar, click on File -> New Project, and you'll see a panel. Look to your left and select Django. All the settings are done for you.


2 Answers

In pycharm open the settings "cmd" + "," and then to "Project Structure" click on "Sources" to include any modules.

like image 169
Paul Avatar answered Sep 28 '22 02:09

Paul


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

like image 24
MattoTodd Avatar answered Sep 28 '22 02:09

MattoTodd