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\
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 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 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.
I'm trying to connect RabbitMQ to Graphite(0.9.9) using https://github.com/somic/graphite-rabbitmq
However, I'm not entirely sure which directory in Graphite the graphite-rabbitmq files should be placed.
When I run carbon-agent-rabbitm1.py I get
Failed to import the graphite package. Please verify that this package
was properly installed and that your PYTHONPATH environment variable
includes the directory in which it is installed.
For example, you may need to run the following command:
export PYTHONPATH="/home/myusername/lib/python/:$PYTHONPATH"
Help would be very much appreciated
The convention with python modules, you can just put the downloaded files in an arbitrary temp directory, cd into that directory, and run:
python setup.py install
The standard distutils package will do the work of making sure everything gets to the right place.
You may also want to download pip which will manage the process of downloading and installing these packages for you, in which case you can then just type:
pip install graphite-web
But aside from all that, you really can put the files anywhere, so long as you add the directory to an environment variable called PYTHONPATH, just like the error message you quoted says.
Unless you've got a specific reason for using the scripts in that github repo, I wouldn't as they appear to be about 3 years old and graphite now has support for RabbitMQ by way of the Twisted Python AMQP library (txamqp), which makes those scripts completely unnecessary.