python installing bluepy to virtualenv - python-3.x

I'm a *nix noob. I'm on Ubuntu 16.04.
I'm trying to install bluepy to a virtualenv. It is currently installed under my user (not a virtualenv). When running pip freeze I see it listed under my user. When I activate the virtualenv and run pip freeze it does not show up. I tried to install it under the virtualenv using the following command: sudo pip3 install bluepy. It returns this:
The directory '/home/todd/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/todd/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
I'm not sure what to do. If responding please add explanations so I can learn something. Thanks!
EDIT:
This answer did not help solve my problem. It was tailored for a Mac OS, not Ubuntu.
pip install: Please check the permissions and owner of that directory

Related

how include a python package in my current project direct under linux? [duplicate]

I know the obvious answer is to use virtualenv and virtualenvwrapper, but for various reasons I can't/don't want to do that.
So how do I modify the command
pip install package_name
to make pip install the package somewhere other than the default site-packages?
The --target switch is the thing you're looking for:
pip install --target=d:\somewhere\other\than\the\default package_name
But you still need to add d:\somewhere\other\than\the\default to PYTHONPATH to actually use them from that location.
-t, --target <dir>
Install packages into <dir>. By default this will not replace existing files/folders in <dir>.
Use --upgrade to replace existing packages in <dir> with new versions.
Upgrade pip if target switch is not available:
On Linux or OS X:
pip install -U pip
On Windows (this works around an issue):
python -m pip install -U pip
Use:
pip install --install-option="--prefix=$PREFIX_PATH" package_name
You might also want to use --ignore-installed to force all dependencies to be reinstalled using this new prefix. You can use --install-option to multiple times to add any of the options you can use with python setup.py install (--prefix is probably what you want, but there are a bunch more options you could use).
Instead of the --target or --install-options options, I have found that setting the PYTHONUSERBASE environment variable works well (from discussion on a bug regarding this very thing):
PYTHONUSERBASE=/path/to/install/to pip install --user
(Or set the PYTHONUSERBASE directory in your environment before running the command, using export PYTHONUSERBASE=/path/to/install/to)
This uses the very useful --user option but tells it to make the bin, lib, share and other directories you'd expect under a custom prefix rather than $HOME/.local.
Then you can add this to your PATH, PYTHONPATH and other variables as you would a normal installation directory.
Note that you may also need to specify the --upgrade and --ignore-installed options if any packages upon which this depends require newer versions to be installed in the PYTHONUSERBASE directory, to override the system-provided versions.
A full example
PYTHONUSERBASE=/opt/mysterypackage-1.0/python-deps pip install --user --upgrade numpy scipy
..to install the scipy and numpy package most recent versions into a directory which you can then include in your PYTHONPATH like so (using bash and for python 2.6 on CentOS 6 for this example):
export PYTHONPATH=/opt/mysterypackage-1.0/python-deps/lib64/python2.6/site-packages:$PYTHONPATH
export PATH=/opt/mysterypackage-1.0/python-deps/bin:$PATH
Using virtualenv is still a better and neater solution!
To pip install a library exactly where I wanted it, I navigated to the location I wanted the directory with the terminal then used
pip install mylibraryName -t .
the logic of which I took from this page: https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/download
Installing a Python package often only includes some pure Python files. If the package includes data, scripts and or executables, these are installed in different directories from the pure Python files.
Assuming your package has no data/scripts/executables, and that you want your Python files to go into /python/packages/package_name (and not some subdirectory a few levels below /python/packages as when using --prefix), you can use the one time command:
pip install --install-option="--install-purelib=/python/packages" package_name
If you want all (or most) of your packages to go there, you can edit your ~/.pip/pip.conf to include:
[install]
install-option=--install-purelib=/python/packages
That way you can't forget about having to specify it again and again.
Any excecutables/data/scripts included in the package will still go to their default places unless you specify addition install options (--prefix/--install-data/--install-scripts, etc., for details look at the custom installation options).
Tested these options with python3.5 and pip 9.0.3:
pip install --target /myfolder [packages]
Installs ALL packages including dependencies under /myfolder. Does not take into account that dependent packages are already installed elsewhere in Python. You will find packages from /myfolder/[package_name]. In case you have multiple Python versions, this doesn't take that into account (no Python version in package folder name).
pip install --prefix /myfolder [packages]
Checks if dependencies are already installed. Will install packages into /myfolder/lib/python3.5/site-packages/[packages]
pip install --root /myfolder [packages]
Checks dependencies like --prefix but install location will be /myfolder/usr/local/lib/python3.5/site-packages/[package_name].
pip install --user [packages]
Will install packages into $HOME:
/home/[USER]/.local/lib/python3.5/site-packages
Python searches automatically from this .local path so you don't need to put it to your PYTHONPATH.
=> In most of the cases --user is the best option to use.
In case home folder can't be used because of some reason then --prefix.
pip3 install "package_name" -t "target_dir"
source - https://pip.pypa.io/en/stable/reference/pip_install/
-t switch = target
Nobody seems to have mentioned the -t option but that the easiest:
pip install -t <direct directory> <package>
pip install packageName -t pathOfDirectory
or
pip install packageName --target pathOfDirectorty
Just add one point to #Ian Bicking's answer:
Using the --user option to specify the installed directory also work if one wants to install some Python package into one's home directory (without sudo user right) on remote server.
E.g.,
pip install --user python-memcached
The command will install the package into one of the directories that listed in your PYTHONPATH.
Newer versions of pip (8 or later) can directly use the --prefix option:
pip install --prefix=$PREFIX_PATH package_name
where $PREFIX_PATH is the installation prefix where lib, bin and other top-level folders are placed.
To add to the already good advice, as I had an issue installing IPython when I didn't have write permissions to /usr/local.
pip uses distutils to do its install and this thread discusses how that can cause a problem as it relies on the sys.prefix setting.
My issue happened when the IPython install tried to write to '/usr/local/share/man/man1' with Permission denied. As the install failed it didn't seem to write the IPython files in the bin directory.
Using "--user" worked and the files were written to ~/.local. Adding ~/.local/bin to the $PATH meant I could use "ipython" from there.
However I'm trying to install this for a number of users and had been given write permission to the /usr/local/lib/python2.7 directory. I created a "bin" directory under there and set directives for distutils:
vim ~/.pydistutils.cfg
[install]
install-data=/usr/local/lib/python2.7
install-scripts=/usr/local/lib/python2.7/bin
then (-I is used to force the install despite previous failures/.local install):
pip install -I ipython
Then I added /usr/local/lib/python2.7/bin to $PATH.
I thought I'd include this in case anyone else has similar issues on a machine they don't have sudo access to.
If you are using brew with python, unfortunately, pip/pip3 ships with very limited options. You do not have --install-option, --target, --user options as mentioned above.
Note on pip install --user
The normal pip install --user is disabled for brewed Python. This is because of a bug in distutils, because Homebrew writes a distutils.cfg which sets the package prefix.
A possible workaround (which puts executable scripts in ~/Library/Python/./bin) is:
python -m pip install --user --install-option="--prefix=" <package-name>
You might find this line very cumbersome. I suggest use pyenv for management.
If you are using
brew upgrade python python3
Ironically you are actually downgrade pip functionality.
(I post this answer, simply because pip in my mac osx does not have --target option, and I have spent hours fixing it)
With pip v1.5.6 on Python v2.7.3 (GNU/Linux), option --root allows to specify a global installation prefix, (apparently) irrespective of specific package's options. Try f.i.,
$ pip install --root=/alternative/prefix/path package_name
I suggest to follow the documentation and create ~/.pip/pip.conf file. Note in the documentation there are missing specified header directory, which leads to following error:
error: install-base or install-platbase supplied, but installation scheme is incomplete
The full working content of conf file is:
[install]
install-base=$HOME
install-purelib=python/lib
install-platlib=python/lib.$PLAT
install-scripts=python/scripts
install-headers=python/include
install-data=python/data
Unfortunatelly I can install, but when try to uninstall pip tells me there is no such package for uninstallation process.... so something is still wrong but the package goes to its predefined location.
pip install /path/to/package/
is now possible.
The difference with this and using the -e or --editable flag is that -e links to where the package is saved (i.e. your downloads folder), rather than installing it into your python path.
This means if you delete/move the package to another folder, you won't be able to use it.
system` option, that will install pip package-bins to /usr/local/bin thats accessible to all users. Installing without this option may not work for all users as things go to user specific dir like $HOME/.local/bin and then it is user specific install which has to be repeated for all users, also there can be path issues if not set for users, then bins won't work. So if you are looking for all users - yu need to have sudo access:
sudo su -
python3 -m pip install --system <module>
logout
log back in
which <module-bin> --> it should be installed on /usr/local/bin/
Sometimes it works only works with Cache argument
-m pip install -U pip --target=C:\xxx\python\lib\site-packages Pillow --cache-dir C:\tmp

why (miniconda) pip install in .local

pip install is installing packages in my user's .local directory, a behaviour that I would like to avoid. Here is my setup:
(base) MYUSER#MYMACHINE:~$ which pip
/home/MYUSER/miniconda3/bin/pip
(base) MYUSER#MYMACHINE:~$ which python
/home/MYUSER/miniconda3/bin/python
An example trying to install bottleneck:
(base) MYUSER#MYMACHINE:~$ pip install bottleneck -v
...
Installing collected packages: numpy, bottleneck
changing mode of /home/MYUSER/.local/bin/f2py to 775
changing mode of /home/MYUSER/.local/bin/f2py3 to 775
changing mode of /home/MYUSER/.local/bin/f2py3.6 to 775
Successfully installed bottleneck-1.3.2 numpy-1.19.0
Cleaning up...
Although I expect bottlneck to be installed in /home/MYUSER/miniconda3/lib/python3.7/site-packages, it actually gets installed in .local instead:
(base) MYUSER#MYMACHINE:~$ ls ~/.local/lib/python3.6/site-packages/bottleneck/
benchmark nonreduce_axis.cpython-36m-x86_64-linux-gnu.so _pytesttester.py src
__init__.py nonreduce.cpython-36m-x86_64-linux-gnu.so reduce.cpython-36m-x86_64-linux-gnu.so tests
move.cpython-36m-x86_64-linux-gnu.so __pycache__ slow _version.py
I hope I have provided enough information to debug this.
A crucial piece of information that I thought was irrelevant is that I am executing these commands in a VNC session. It was brought to my attention that the environment variables when a new terminal is launched within the VNC session are inherited from the terminal that created the VNC session.
For more information:
https://unix.stackexchange.com/questions/400329/gnome-terminal-inherits-some-environment-even-with-env-i-on-a-vnc-session
In my case, the environment variables (i.e. PATH, PYTHONPATH) were messed up due to the above reason. Solved now

How to fix conda update conda permission error

~$ conda update conda
Solving environment: done
## Package Plan ##
environment location: /home/david/anaconda3
added / updated specs:
- conda
The following packages will be UPDATED:
conda: 4.4.10-py36_0 --> 4.4.11-py36_0
Proceed ([y]/n)? y
Preparing transaction: done
Verifying transaction: done
Executing transaction: failed
ERROR conda.core.link:_execute(481): An error occurred while uninstalling package 'defaults::conda-4.4.10-py36_0'.
PermissionError(13, 'Permission denied')
Attempting to roll back.
Rolling back transaction: done
PermissionError(13, 'Permission denied')
I was trying to update conda on virtualbox ubuntu 16.04 and this permission error came up. I tried sudo conda update conda but it returns sudo: conda: command not found. I'm not sure where to go from here.
I got the same error and solved it by this:
sudo env "PATH=$PATH" conda update conda
All conda commands must be run without super user privileges. That's why sudo conda command doesn't work.
You may have run conda installation bush file with super user privileges while installing. The user (david) running conda doesn't have write permissions to paths(/home/david/anaconda3) it needs to modify in the environment, then conda can't do anything. To solve this problem you need to change permissions to paths (/home/david/anaconda3).
To change permissions to paths (/home/user/anaconda3) using:
sudo chown -R user /home/user/anaconda3
I solved this problem by right clicking on Anaconda Prompt, selecting "Run As Administrator", and typing the command that I want to execute.
This problem arise if at installation time, we select an option install for all user anaconda. It can be solved as I mentioned above - run it as Administrator and type the conda commands for install, updating the packages.
It's Permission denied, So just sudo chown -R frazier:frazier /home/frazier/anaconda3
PS: change 'frazier' to your user name.
conda install numpy
{
Executing transaction: failed
ERROR conda.core.link:_execute(502): An error occurred while uninstalling package 'defaults::conda-4.5.4-py27_0'.
OSError(13, 'Permission denied')
Attempting to roll back.
Rolling back transaction: done
OSError(13, 'Permission denied')}
solution:
to change the permission to conda, use the command :
sudo chown -R nikhil /home/nikhil/miniconda
chown command changes the permission of miniconda to use sudo.
now you have the permisssion to access sudo..
now use:
conda update conda
now
Executing transaction: Done
You have installed Anaconda with sudo or root user. You need to install it with normal ubuntu/<Your username> user.
Remove or take backup of the already installed Anaconda (/home/<user>/anaconda3).
With normal mode install anaconda ( bash conda_installer_script ) .
Check .bashrc for this line and validate it.
export PATH="/home/<username>/anaconda3/bin:$PATH"
If not add it with proper anaconda path .
Reload .bashrc file and check conda is working by conda list command.
Now you can do conda update conda
I too had this error and resolved it by doing the following things - a little strange but worth a try.
1. Run as administrator
2. Run the code below to specifically update package in an environment -myenv
$conda install --name myenv numpy
3. For me the environment was running hence it was not updating, once I closed my running workbooks, and ran Point 1 and 2 .. it worked :)
if you have this error message during package installation in anaconda then follow the given step:
open the anaconda prompt by right click.
select the run as administrator.
type the command for install package.eg conda install numpy
Run Anaconda Prompt using "Run as Administrator" option and then
run the command -> conda update conda
Then go back to starting Anaconda Prompt as usual and I believe everything should be fine.
Also, don't forget to add Anaconda3 path to Environment variables.

Cannot run jupyter notebook in Ubuntu

I have installed jupyter notebook using:
sudo pip3 install jupyter
It seemed to work but I got the error:
The directory '/home/user1/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/user1/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag
When I run it:
jupyter notebook
I get the error:
Error executing Jupyter command 'notebook': [Errno 8] Exec format error
Try:
pip3 install jupyter --user
This will install jupyter to your home directory. This removes the ownership issue. In my case the installation directory is:
~/.local/lib/python3.6/site-packages.
I use Linux Mint, which is a fork of Ubuntu.

Error in creating virtualenv in ubuntu 16.04.2 LTS

Hello I am getting following error during virtualenv creation.
Here is the error:
$ mkvirtualenv cv
ERROR: virtualenvwrapper could not find /usr/local/bin/virtualenv in your path
Before this I was getting some weird message during the run of following commands:
sudo python get-pip.py
sudo pip install virtualenv virtualenvwrapper
Here is the weird message:
The directory '/home/myusername/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/myusername/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
If I run this command sudo apt install virtualenv or virtualenvwrapper then I don't get the above weird message. but this don't help me to create virtualenv
python path is /usr/bin/python
Can anybody help me to figure out the issue by providing detailed command?
First, let's clear your "weird" message. It means that you've already used sudo -H before and sudo changed ownership for some of your files to root. Take the files back with the command
sudo chown -R myusername /home/myusername
(change myusername to your real login name; I used the name you've used in your question.)
After that upgrade pip and follow installation instructions for virtualenv and virtualenvwrapper:
sudo pip install -U pip setuptools virtualenv virtualenvwrapper
source /usr/local/bin/virtualenvwrapper.sh

Resources