I just downloaded django and installed it into C:\Python27\Lib\site-packages So now my site-packages directory seems rather unorganized with 5 separate folders a bunch ot text files and a python script. Should I create a sub directory in site-packages for the django package and store everything in there? If I do that will the python intrepeter know to look in the Django directory in the site-packages directory for the django package? Or will I have to change some environment variables around?
Thank you.
I'm not sure if you're asking it because this is something you need to know because of some complex setting you have. In case you are just want to install Django, you should follow the install instructions from their site:
pip install Django
the directory order in site-packages is an internal mechanism of your Python build and I don't think you should change it, unless you want to create your own package and want to learn more on how python find installed packages (and if this is the case I would start reading this document: http://docs.python.org/2/distutils/index.html)
As suggested in the comments to your question, and also in the documentation of Django, you should consider using virtualenv, especially when developing a webapp which will get deployed on a server with a specific Django version. Over time you'll see that you want to create other apps that require different versions of modules, and to still support the already existing apps you will need to use virtualenv.
Related
i am new to Python programming language and Django. I am learning about web development with Django, however, each time I create a new project in PyCharm, it doesn´t recognize django module, so i have to install it again. Is this normal? Because i´ve installed django like 5 times. It doesn´t seem correct to me, there must be a way to install Django once and for all and not have the necessity of using 'pip install django' for each new project I create, I am sure there must be a way but I totally ignore it, I think I have to add django to path but I really don´t know how (just guessing). I will be thankful if anyone can help me :)
pycharm runs in a venv. A venv is an isolated duplicate (sort of) of python (interpreter) and other scripts. To use your main interpreter, change your interpreter location. The three folders (where your projects is, along with your other files) are just that. I think there is an option to inherit packages. I like to create a file called requirements.txt and put all my modules there. Comment for further help.
In conclusion, this is normal.
There are 2 ways of starting your project in PyCharm.
To use a virtual environment where you have to install the external libraries into this environment.
To start using the existing interpreter. (If you chose this option you don't have to install it again installing it only once globally would be enough)
So when you start to create a new project choose the existing interpreter.
Doing this will not require you to install it every time(But is not recommended for big projects as there would dependencies on different versions of libraries).
I made a package that bundles some utilities I'm using across projects. What's an easy way to import this package each time I start a new project?
There's some private work data stored as variables in there, so I won't be uploading it onto PyPi.
I am using Python 3.7 and PyCharm, and in Project Interpreter attempted to put the /zhou_utils/dist as a 'URL' of repositories it searches for, but it threw an error.
Another solution I saw someone present was to change their local PATH, but I don't have admin privileges on my work computer so don't know if I can do that.
Running this in my terminal from my 2nd project worked:
pip install -e C:\Users\Uname\PycharmProjects\zhou_utils\
I have 10 django projects that use over 50 django apps. Each app is separated in its own project and added to pypi and is getting use by few project. Every thing if fine except every time i work on a project and i want to change some code that is in one of my modules (that happens a lot) I have to open the module project, make my changes, test and publish to pypi then come back to my project update requirements.txt file and get the updated module from pip.
I'm looking for a way to be able to edit module right away from all of my projects. For example instead of getting it from pypi i want to get it from git and be able to commit to the git repository in my venv folder!
I know it seems a little bit crazy but i could save a lot of time! publisher and user of all of the modules is me so I don't mind the user to be able to change as well.
Any thought or suggestion will be appreciated. Also any none pip solution will be fine as well like writing a custom shell script.
I don't know about editing in your venv folder, which I think is not a good practice, but you can install from github by pip. You can use 'pip install git+https://github.com/urltoproject/repository.git'. Fill in the necessary details yourself of course. This also works with other systems like gitlab. You could have a separate development requirement file and a production requirement file to separate the two environments, or you install on the commandline directly with pip.
I just finished my first Django-app and I now have a .tar.gz file. (It's my first one ever: :'))
After having the .tar.gz file I was like ok... now what's next? How do I install this? I found this question: How do I install Python/Django Modules? And I was reading #Miku answer to the question and I was thinking: Ok, if I just do pip install --user django-polls/dist/django-polls-0.1.tar.gz (from Advanced tutorial: How to write reusable apps documentation!) that means that my django proyect should be able to find my app after I add the app to
INSTALLED_APPS?
Because I was following the tutorial and I had the app folder right next to manage.py file. And know pip says my app is installed and not folder has been created in my project directory.
If this is a really stupid question, please, pardon me, I'm really new to django. :-)
When you install a python package as a library, it's installed to the python's packages folder, so it can be used from anywhere in the system.
So yes, your Django project should be able to find your app when you add its name in INSTALLED_APPS. If your app doesn't have its own models, you don't even have to include it in the installed apps, and just import from it when you need to use it.
I'm not sure what system you are on, but in Linux, usually installed python packages are located in /usr/lib/{PYTHON VERSION}/site-packages/
(just for a reference)
I'm using the Django Registration class, it's great, but the last version shipped with an issue and it's no longer updated
I've installed it on my path (downloaded it then python setup.py install) then added it to my projects installed apps
I'm on debian, and It's copied itself to /usr/lib/python2.5/site-packages/registration
So far so great, but editing (hell, even deleting) has NO effect on my project
I'm guessing when you include a class in the django installed apps it's copied somewhere, but where?
As always, thanks for your time!
You could try the oldest trick ever to figure out where it's coming from:
import registration
print registration.__file__
I would suggest that you try the following workflow:
Create a new virtualenv for every project you start (use --no-site-packages)
Install all your dependencies (including django) in the project's virtualenv
Use pip install -e to install things you need to have an editable version of.
Alternatively, fork the project, and install using pip install -e hg+http://...
I'm guessing when you include a class in the django installed apps it's copied somewhere, but where?
That's completely a wrong guess.
A better guess is that your download directory is on your Python path.
Somehow you had two copies (or more) of the module.
You've deleted some, but not all of the copies.
Keep searching on your PYTHONPATH for all the others. Search every directory in sys.path.
Note that .pth files in your site-packages directory are also part of your PATH.