Install Tkinter in virtualenv on Linux without Sudo access - python-2.7

I am using a virtualenv on a Linux machine. I don' have sudo access so I can use pip only.
I tried:
pip install python-tk
But this resulted in this error message
Collecting python-tk
Could not find a version that satisfies the requirement python-tk (from versions: )
No matching distribution found for python-tk
How can I install Tkinter in virtualenv on Linux?

You can't install tkinter using pip because tkinter is an interface to a C++ library called Tk, whereas pip is coded with Python.
Luckily you do not have to worry about the above statement because tkinter comes as a built-in library for the standard Python distribution.
So what you have to do is:
Go to your virtualenv directory: cd to_your_virtualenv_directory
Activate it: source bin/activate
Access your python shell within it: python
Then import tkinter as tk
Note:
Depending on your settings, maybe when you type python you will notice you are prompted to work with Python 2.x instead. In that case, just type this: import Tkinter as Tk. If, however, typing python leads you to use Python 3.x (as I set it on my machine), but you prefer to work with Python 2.x then simply type python2 instead of python.

Related

My pip isn't installing my packages correctly

It's messing all my installation up all of a sudden.
I've installed it using pip BeautifulSoup4 for example
It keeps installing- when I use python and import it; it doesn't import it properly.
However; somehow my requests works. I think I messed up my PATH variable.
>>> import sys
>>> print '\n'.join(sys.path)
/usr/local/Library/Python/2.7/site-packages
/usr/local/lib/python2.7/site-packages
/Library/python2.7/site-packages
/Library/python2.7/site-packages/usr/local/lib/python2.7/site-packages
/usr/lib/python2.7/site-packages/Library/python2.7/site-packages
/usr/lib/python2.7/site-packages/Users/biplovdahal/Library/Python/2.7/lib/python/site-packages
/Users/biplovdahal/Library/Python/2.7/lib/python/site-packages
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/Library/Python/2.7/site-packages
^ How would I set my pip to listen to a specific site-package and keep installing my future modules in that one site-packages. I don't want it mixed up anymore. I'd like to also get rid of all the permission problem as possible so I can safely install my package and use it.
You can call pip by prefixing python path like this
/usr/local/bin/python pip install <package name>
The above command wiill place site-packages in /usr/local/lib/python2.7/site-packages/ folder . if you want to change it to install to someother library , you change the python path in the pip command

does pip install -U break virtualenv?

I have a virtualenv where I'm running python 2.7.13. I did install numpy a while ago. Today I wanted to install statsmodels as well in the same virtualenv. That's why I did (according to the webpage):
pip install -U statsmodels
and several packages where updated (numpy among others). I forgot that the -U forces to install the newest version. Since numpy was updated to numpy 1.13.3 I'm not sure if this broke a dependency. Is the forced version 1.13.3 not suitable for the virtualenv? If so how can I remove it and install the correct one. If I'm running
pip uninstall numpy
followed by a
pip install numpy
it says:
pip install numpy
Collecting numpy
Using cached numpy-1.13.3-cp27-cp27mu-manylinux1_x86_64.whl
Installing collected packages: numpy
Successfully installed numpy-1.13.3
Yes, the compatibility with Python is guaranteed: look at the filename of the wheel that is installed: numpy-1.13.3-cp27-cp27mu-manylinux1_x86_64.whl. That matches the Python version you're using (including your OS).
As for statsmodels and the upgraded NumPy: if statsmodels requires numpy 1.13.3, you're fine; that's the whole point of a virtualenv: it doesn't break any other dependencies/virtualenvs you might have set up. It is unlikely you have another package in the same virtualenv that requires a lower version of NumPy.

No module named 'matplotlib.pyplot'; 'matplotlib' is not a package

Have found a similar issue, however haven't found proper solution.
Here's a code:
import matplotlib.pyplot as plt
plt.plot([1,2,3],[4,2,5])
plt.show()
Run, got the message:
ImportError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package
I run Linux Mint 18 with preinstalled python-2.7 and python-3.5 (I use python3), before that I was installing modules with a simple sudo apt-get install method and that worked great.
Before running this the code above, I've installed matplotlib in a usual way sudo apt-get install python-matplotlib. As it haven't worked out, started to look for solution.
Python location
which python3 /usr/bin/python3
Current Matplotlib installed
sudo find /usr | grep matplotlib /usr/lib/python3/dist-packages/matplotlib
My tries:
1) I've removed matplotlib with autoremove, and tried to make it sudo apt-get install python3-matplotlib instead. Didn't worked out.
2) Used: pip3 install matplotlib or sudo pip3 install matplotlib. Received errors like:
command python setup.py egg_info failed with error code 1 in /tmp/pip-build- ....
3) Then I found another solution:
sudo apt-get install virtualenv
virtualenv -p /usr/bin/python3 py3env
source py3env/bin/activate
pip install matplotlib
Same outcome.
Haven't tried to use import sys sys.path.append('/usr/lib/pymodules/python2.7/')(proposed in link above), but as I am not sure what exactly this command does (quite a newbie to python and programming itself) - haven't risked.
If you are using pycharm and have matplotlib.py in your current working directory than you get this error. Just delete or rename the matplotlib.py file and it will work.
don't name any file as matplotlib.py within your working directory
In your working directory, check if there is any file matplotlib.py
Delete that file and import matplotib again. That should work.
simply install:
python -m pip install -U pip
python -m pip install -U matplotlib
I had the same problem reasons in my case were
python 3.8.2 with matplotlib that I downloaded was for 3.7. Make sure they are the same.
python 64 bits version with matplotlib 32bits. Make sure they are the same
Use python -m pip install package_which_you_need to install packages for Windows
Make sure to add to PATH the environment variables I forgot to do in my case
pip version was old use
Use python -m pip install --upgrade pip to upgrade pip to the latest for Windows
I saved the file name as matplotlib.py. Try to avoid that
Finally I typed matplotlib.pyplot as matplotlib.plyplot remember to check for typos first. The error message looks similar even though I corrected all the steps above.
ModuleNotFoundError: No module named 'matplotlib.pyplot'
ModuleNotFoundError: No module named 'matplotlib.plyplot'

Unable to import docx in python3

I have installed both python2 and python3 in my windows machine. I wanted to use the python-docx, so I installed it using pip install . But I am unable to use it in python3. I get these results when i try to import in Python2:
]1
In Python3 :
]2
Python packages are installed in a particular Python installation. You have two Python installations and it looks like python-docx is installed in only one of them. What you need to work out is how to target the Python 3 installation for the python-docx install.
This question seems to address how to manage that.

Python3 pyserial library

I am working on small python scripts. Basically i am not a python programmer and very new to it. Recently i have been working on IOT protocol MQTT. I have installed a open source MQTT clinet based on python3 in my raspberypi board. And now i am facing a problem. I have python 2.7 and 3.2 installed.
My MQTT client work with Python3.x and i want to use pyserial library also which i am not able to , i am getting a error
Serial module not found
I goggled a bit and end up here.. Now it say that you need to install pip3 in order to install pyserial for python3.x.
I tried to install pip3 using this link , but end up installing pip2 using
pip install -U pip
I feel totally being messed up now. I just want to use pyserial while working with python3.x version.Can any one suggest me how?
Edit 1:
On Linux, Mac OS X and other POSIX systems, use the versioned Python commands in combination with the -m switch to run the appropriate copy of pip:
python2 -m pip install SomePackage # default Python 2
python2.7 -m pip install SomePackage # specifically Python 2.7
python3 -m pip install SomePackage # default Python 3
python3.4 -m pip install SomePackage # specifically Python 3.4
I recently came through this documentation given here . But it even give a error to me /usr/bin/python3 : NO module named pip. main : 'pip' is a package and cannot be installed directly.
Assuming you're using raspbian on your pi, you could install pip3 from the normal repositories:
apt-get install python3-pip
You can get the serial module the same way:
apt-get install python3-serial
I succeeded installing pyserial2.7 on a Mac running Yosemite and Python3.4
I entered the pyserial-x.y directory and run:
python3 setup.py install
I got lot of errors that I corrected one by one by editing the files containing the syntax errors. Only 2 types of errors are encountered:
- print needs ()
- except needs as instead of ,
So by correcting the dozen of errors with some patience, installation finish correctly.
I wonder why a syntactically correct version for Python3 is not ready!