How do I add Django-dev from pip to site-packages? - python

I installed Django with
C:\Python27\Lib\site-packages>pip install -e git+https://github.com/django/django.git#egg=django
Unfortunately some programs (such as PyDev), work "easier" when your packages are in the site-packages directory.
How do I force pip to install it in site-packages, rather than provide just a Django.egg-link file there?

There's two things here.
First you need to get rid of the -e unless you plan on hacking on django itself. See here: http://www.pip-installer.org/en/latest/usage.html#edit-mode
Also with pydev you often need to tell it to reindex your site packages after installing something new. To do this you need to go into the interpreter settings and choose the interpreter for your current project. IIRC you can just open it, hit apply and it will reindex your site packages.
Hope that helps :)

Related

How to use python library without installing it

I'm using AWS for work with Anaconda in it. I don't have permission to install any python library (I mean, I requested it and it's taking ages) so I'm trying to see if there's a way around it.
I'm trying to install xgboost, is it possible to do so without actually installing it? I thought maybe copying and pasting the base code, but it's a bit messy I guess?
Any better recommendations?
I tried using a virtual environment (venv) and it doesn't seem to work... it's not allowing me to create a virtual env, I guess it's because of the permits I said before.
Edit: I basically cannot install anything (I can't even access google actually, just the company approved websites). The first idea, of pasting the base code, I will have to send it over from my personal email to my work email so I can get it there, but it's not very simple either.
Download Package which you want to install
unzip and cd into folder
run python setup.py with --user flag
If you have access to the site-packages directory, you can copy the package directly into there, as you suggested. I guess installing from a wheel also wouldn't work?
You could also just redownload python into a directory you have access to and start from there.
Also, does Anaconda use venv? I've always used conda create to make an anaconda virtual environment.
I have used some modules in python (pexpect) without actually installing the module, but instead having the module file within the same folder where I have the project.
And just calling the import (module) in the code.
i'm not sure if it can work for you, but you should give it a try.

How can I escape from python environment hell?

I don't know how I've gotten here but I have many competing installations of python on my Ubuntu 16.04 path. Some I use, some I don't.
I'm at the point now where I want to clean up things to save headache when troubleshooting issues but I don't know any strategies or tools of tackling this.
What is the best way I can find out which environments are being used and not used?
How can I determine which python directories are being pointed to and which ones are abandoned?
Whats a quick way I can get a list of non-standard packages installed to each environment?
Here is what you can try
which python usually for python2.x and which python3 for python3.x.
Then decide which version you want to use by default then you can use export python='Your required python interpreter path' for permanent changes, or you can use alias python=PATH for temporary usage.
Also see where the pip and pip3 are pointing at by using which pipX. Thus you can use one of them to install required packages.
I would recommend you to use virtualenv or pipenv so that you get more fine grained control over the interpreter selection according to the need of your project.
Note do not uninstall any of the above python packages without some research as there might be system dependencies thus breaking your system.

How to delete all python software except what is needed by OS

In this SO post I outlined my problems, and I would like to try and solve them by getting rid of all my downloaded python launchers, modules, versions, pip etc (for python 2 & 3) and start afresh. My only problem is that macOS comes pre-loaded with python 2 and I don't think I can or should get rid of that, but I do have other versions of python 2 installed that I do want to delete.
Is there any help that you can offer that will tell me what to delete and what not to?
Should I need to use 'sudo' at all during my uninstalling?
Are there any tests to ensure certain things are completely gone?
Please keep answers fairly simple to understand implement.
When I reinstall the things I need, is it better to do it all via home-brew, then pip; instead of downloading from safari, unless necessary?
If you installed using sudo (or typed your password into an installer), you'll need this to uninstall too. Mac python is in /usr/bin/python and /usr/lib/python*. Yes it can be good to install via homebrew, although I've had good success with the Anaconda distro of Python. The important thing is setting you PATH and PYTHONPATH variables in ~/.profile or ~/.bash_profile so that it sees your custom installed Python before it sees the system install.

how to check what packages are used to include in a requirements.txt file?

I'm starting to dive into python but I'm a bit confused with how the requirements.txt file work. How do I know what to include in it?
For example, the current project I'm working on, I only installed Flask. So do I just add only flask to that file? Or are there other packages that I don't know about - if so is there a way to find out (e.g display a full list)?
You could run pip to get the list of requirements for your project.
pip freeze > requirements.txt
You could just "grep" the Python source files in your project for "import " to get an exhaustive list of packages you use. Remove the obvious ones that are part of the standard library, like datetime or whatever, and the rest are what you might include in requirements.txt.
I don't know of a more "automatic" way to do it; another way might be to set up a clean virtualenv or other sandboxed install of Python with no extra packages, and try installing your software in there using only your requirements.txt.

Installing nosetests - permission denied

Trying to install nosetests as per the learnpythonthehardway tutorial, I'm having problems. Any clues on what I should try next?
$ easy_install nose
Searching for nose
Best match: nose 1.1.2
Processing nose-1.1.2-py2.6.egg
nose 1.1.2 is already the active version in easy-install.pth
Installing nosetests-2.6 script to /usr/local/bin
error: /usr/local/bin/nosetests-2.6: Permission denied`
One question about installing that I have: if I have something saved in a random location on my computer, can it be imported into a python script regardless of where it is? So if I execute runthis.py that's in a folder called "projects", and I have from setup tools import setup as the first line of the program, does setup tools have to be anywhere in particular (such as the "projects" folder) for python to find it?
Are you able to use sudo?
If so, simply use sudo easy_install nose to install as root.
If not, you'll need to install somewhere you can write to, not the default location which you don't have permission to modify. This can be done easily in the traditional way, or using virtualenv which can a bit trickier to get set up initially.
As for the second question, no, python will only find things that are in directories found in sys.path, which is set to the contents of the PYTHONPATH environment variable plus the installed python's own library directories by default.
It is often (highly!) advisable to set up your own "local" repository of packages, for whatever language system (be it Python or otherwise) that you are using. Leave the "system installed" packages, whatever they might be, completely alone ... in case some uber-important system tool (the package-manager, anyone?) might also be using them and might be dependent on them.
The means of doing this vary from language to language, but they'll be documented somewhere all the same. You might even find that the "distro" that you're using has already anticipated this requirement and has set-aside some agreed upon location, e.g. "/usr/local/..." just for your own personal use.

Categories

Resources