Installation of tkinter on python3 - python-3.x

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.

Related

Install the latest version of my package from working directory into my local environment using Python's poetry

It's extremely useful for the development workflow to be able to build and install the latest version of a package into a local environment. You can then interactively validate and debug by importing this latest version into a Python shell or a Jupyter notebook. The problem is I've recently adopted Poetry and cannot figure how to do this now. So...
How do I install the latest version of my package from the current working directory into my local environment using Poetry?
Moving on from setuptools
Back in the day, I used to always use setuptools and it worked great. I'd put a setup.py file in the root of my repository, create a virtual environment (let's say using conda) for the project, and do...
pip install -e .
From here, I could fire up a python shell, or even configure a jupyter kernel to use this virtual environment, and I'd always have the latest version of my package to interact with.
Now setuptools has its limitations, and we've since moved on to Poetry to more tightly control dependencies and handle more sophisticated build needs and such.
The problem with poetry
If you look up what's the pip install -e . equivalent in poetry you will find this issue. Looks like the creator of poetry thinks installing directly from source like this is a hack and has no interest in supporting it. (BTW: I've tried poetry build and then pulling out the setup.py file like he suggested and it does not work)
Linking directly to source is not necessary, I'm willing to run an install command to get the latest version of the package. And when I do this with poetry, it appears to work.
cd root/of/my/project
poetry install
Installing dependencies from lock file
No dependencies to install or update
Installing the current project: my-project (0.4.8) <-- this is the latest version according to the source code in the working directory
The problem is that if I open a Python shell and try and import my package for instance, it is linked to the last version of my package that installed from a remote artifact repository (via pip install my-package) – not what's in my working directory.
python
...
>>> import my_package
>>> my_package.__version__
'0.4.7`
Now, even though I'm using poetry I'm using a conda environment to specify the Python version for my project and then installing, and using, poetry from inside that.
source activate my-package
(my-package) ... $ poetry update
I also know that poetry (not very transparently) can create and manage its own virtual environment on your behalf. I thought maybe the reason this is not working is because I need to be inside this environment (whereas I was only inside my conda environment, while poetry is installing the 0.4.8 version of my package within the virtual environment it manages).
I tried both shell and run to test this out. I get the same result.
poetry shell
Virtual environment already activated: /Users/U6020643/.conda/envs/my-package
Python 3.8.5
...
>>> import my_package
>>> my_package.__version__
'0.4.7`
What gives?
The way I fixed this: I stopped using conda to manage the Python version for projects that involve poetry and instead use pyenv.
Below is how I made that work. This was very helpful!
1. Removing conda as default environment manager.
This involved removing conda base activate from ~/.bash_profile.
Now open a new shell and verify that there's no conda environment prefix, e.g. (base) ... $.
2. Installing pyenv using Homebrew
Had been awhile, and an OS upgrade or two, since I interacted with Homebrew. Needed to do some housekeeping.
brew cleanup # This made it so that brew update didn't take forever
brew update
brew upgrade
brew cleanup
Then...
brew install pyenv
3. Install Python version(s)
Let's say you need/want Python 3.
pyenv install 3.8.5
4. Set the local Python version for your project
cd your/project/root/
pyenv local 3.8.5
5. Install poetry
See here.
6. Use it
Now install and use shell. Check the version -> hey it works!
cd your/project/root
poetry install
poetry shell
my_package --version # Package has a CLI.

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

can't uninstall python3 in macOS

I am having trouble with my current python, so I wanted to uninstall my python and install the latest version. I installed with homebrew, so I uninstalled it with homebrew and reinstalled python 3.8.1 with the installer from the official site. Python3.8 was installed, but my python3 was not upgraded.
~ which python3
/usr/bin/python3
~ python3 --version
Python 3.7.3
I know I'm not supposed to(and I can't) manually delete things inside /usr/bin. What am I supposed to do?
When you installed Python with homebrew it told you this:
Unversioned symlinks python, python-config, pip etc. pointing to
python3, python3-config, pip3 etc., respectively, have been
installed into /usr/local/opt/python/libexec/bin
If you need a reminder, post install, you will get the same message if you run:
brew info python
It says "unversioned links are in /usr/local/opt/python/libexec/bin". That means, if you want to run Python without specifying the version, i.e. if you want to type this:
python
and this:
pip
to start Python 3 and its corresponding pip, you need to make sure your PATH has /usr/local/opt/python/libexec/bin at the start, i.e.
export PATH=/usr/local/opt/python/libexec/bin:$PATH
I could not uninstall the python3 in /usr/bin but found a workaround to give the python3 in /usr/loca/bin precedence by setting the PATH env variable as PATH=/usr/local/bin:$PATH. This gives binaries in /usr/local/bin precedence. Not a full fledged solution, but got me moving.

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.

Slurm: Installing python 3 modules when pip3 not available

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.

Resources