Slurm: Installing python 3 modules when pip3 not available - python-3.x

The GPU cluster I'm working off of includes both python 2.7 and python 3.5. pip and easy_install are both provided to allow local modules to be installed to a .local directory. For whatever reason, pip3 is not installed.
How can I install python 3 modules without root access given that pip3 is unavailable?
Thanks

Pycharm community is a free IDE. You can install pycharm first. And then, use pycharm to install other modules.

Related

PIP and python installing packages

I have a CentOs system with both Python 2.7 and Python 3.4 installed. I do not have information regarding how these were installed.
However, this is the response when the following commands are issued:
whereis /usr/bin/python3
python3:
/usr/bin/python3.4
/usr/bin/python3.4m
/usr/lib/python3.4
/usr/lib64/python3.4
/usr/include/python3.4m
whereis /usr/bin/python2.7
python2:
/usr/bin/python2.7
/usr/bin/python2
/usr/lib/python2.7
/usr/lib64/python2.7
/usr/include/python2.7
/usr/share/man/man1/python2.1.gz
I am uncertain how to use PIP in this setup. Python documentation for PIP mentions it assumes that your environment is virtual.
If I want to install a module in python3.4 using PIP, what are the steps?
1. sudo as root?
2. set environmental variables?
3. etc...
Installing a Python package is fairly straightforward, you need to first verify that it's not already packaged by your distro, in your case:
yum search <module_name>
Those packages are generally named like: python-<module_name> for a Python 2 module and python3-<module_name> for a Python 3 module.
If it doesn't exist as a package, you can then rely on PyPI:
python3 -m pip install <module_name> --user
From my answer here
Let's break the this command in two parts:
python -m: Allows modules to be located using the Python module namespace for execution as scripts. The motivating examples were standard library modules such as pdb and profile. See PEP 338
--user : By default Python installs Python packages to system directories which requires root privileges, to avoid using sudo pip install (which is not recommended by the way) use this flag to make pip install packages in your home directory instead, which doesn't require any special privileges.
As a side note, if you have multiple versions of Python installed, keeping track of which Python version version pip is bound to can be a PITA, hence python -m, in this case you're sure that it's the pip bound to the Python called which will be executed.
While the previous method works (kinda), it's advised to use virtual environments because many Linux distributions (including CentOs) rely on some Python modules and you don't want to modify them unless you know what you are doing or you absolutely want to break your System.
Additionally, if you only want to "Install and Run Python Applications in Isolated Environments", you can check out pipx.
I always use pip3 when I want to directly refer to python3.
If I want to install a module in python3.4 using PIP, what are the steps? 1. sudo as root? 2. set environmental variables? 3. etc...
just this
sudo apt install python3-pip
pip3 install xyz

Why virtualenv shows all packages installed and do not install modules in virtualenv?

Question
I am not sure why when virtualenv active, pip freeze stills showing all modules when it suppose NOT to. What am I doing wrong?
On the terminal
I tried two ways to create a virtual env:
virtualenv my-virtualenv
virtualenv --no-site-packages my-virtualenv
then activate it
source my-virtualenv/bin/activate
Results
Both show all packages (when they suppose not to). Running command pip freeze I get:
(my-virtualenv)$ pip freeze
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7.
actionlib==1.11.9
angles==1.9.11
bondpy==1.7.19
camera-calibration==1.12.20
camera-calibration-parsers==1.11.12
catkin==0.7.6
cv-bridge==1.12.4
diagnostic-analysis==1.9.2
diagnostic-common-diagnostics==1.9.2
diagnostic-updater==1.9.2
dynamic-reconfigure==1.5.48
gazebo-plugins==2.5.13
gazebo-ros==2.5.13
...
rosnode==1.12.7
rosparam==1.12.7
rospy==1.12.7
rosservice==1.12.7
rostest==1.12.7
rostopic==1.12.7
rosunit==1.13.5
roswtf==1.12.7
tf2-ros==0.5.16
topic-tools==1.12.7
xacro==1.11.2
Running
(my-virtualenv)$ which python
/home/user/.../my-virtualenv/bin/python
(my-virtualenv)$ python -V
Python 2.7.12
and
(my-virtualenv)$ which python3
/usr/bin/python3
(my-virtualenv)$ python3 -V
Python 3.5.2
Hence, I even can use python3 when virtualenv is activated but it uses the pc installed module. Moreover, new installed packages are install in the pc and not the virtualenv and I can't install python3 in the vitualenv because it "exists" already (but in the pc).
I was having the same issue and it was because, somehow, Python configuration of ROS was generating it.
I solved it removing the source commands of ROS from the ~/.bashrc. E.g.:
source /opt/ros/melodic/setup.bash
source $HOME/ROS/aslam_ws/devel/setup.bash
By the way, I realised that, before changing anything, creating the environment from PyCharm works properly too (when in the terminal I still had the issue).
There must be a better solution but I haven't found it yet.

How to install modules in Python 2.7 insted of Python 3.6?

I have two versions of Python in my laptop. Python 2.7 and Python 3.6. If install a module this is installed only in Python 3.6.
I would like to install modules in Python 2.7 through pip but I don't know how to do it.
I want to install right now GDAL and Fiona for Python 2.7 in Ubuntu 17.04.
If Python 2.7 is well installed on your system, you should have python2 and/or python2.7 commands and you could run the following:
python2.7 -m pip install <your-packages>
To make sure you are running the correct python version, you can use python2.7 --version
Better use virtual environment for this.
Follow this link https://realpython.com/blog/python/python-virtual-environments-a-primer/
You can set python version to use in virtual env using
virtualenv -p path/to/python2.7 env_name
Activate this env using . env_name/bin/activate then,
Use pip install package_name to install libraries inside virtual environment

Use or install different versions of python3 pip

I'm trying to install packages for my python 3.5.0 versus my python 3.4.3
I can run both by typing either python3.4 or python3.5
I have pip2 and pip3. I also ran the script sudo easy_install3 pip, which made me be able to use pip3.4 But I am still having trouble installing modules for python3.5. pip3 just installs for python3.4
I am looking to install termcolor for python3.5 and I am having no success. Can anyone help?
I am on Windows, and you appear not to be, but maybe the following will help.
If pip is in your system's equivalent of python35/Lib/site-packages, then python3.5 -m pip should run pip so that it installs into the 3.5 site-packages.
If you do not have pip in the 3.5 site-packages, copy its directory, along with its dependencies (pip....dist-info/, setuptools/, setuptools....dist-info/, and easyinstall.py) from the 3.4 site_packages.
Or, if pip3 or even pip3.4 is in python35/Scripts, run it with its full path name so you are not running the 3.4 version.

Installation of tkinter on python3

I'm using Fedora 21. Installed the python3-tkinter package using yum install python3-tkinter. The package gets stored in the /usr/lib64/python3.4 directory. Is there a way to use pip to install tkinter?
Have a virtualenv setup with python3. When I try to run my program within that virtualenv I get:
ImportError: No module named 'tkinter'.
Does it make sense to copy the package directories from /usr/lib64/python3.4 to the site_packages folder associated with the virtualenv?
I was using python 3.3.2 interpreter. Turns out the default packages installed when running the command yum install python3-tkinter are set to work with python 3.4.1 interpreter. Configuring my virtualenv to use the python 3.4.1 interpreter proved to be the solution as the python interpreter was then able to find the required libraries in it's path.

Resources