[Tutor] Need help with a virtual environment mess

Jim jf_byrnes at comcast.net
Mon May 7 12:16:16 EDT 2018


On 05/06/2018 05:16 PM, boB Stepp wrote:
> On Sun, May 6, 2018 at 11:05 AM, Jim <jf_byrnes at comcast.net> wrote:
>> In a prior thread you guys helped me fix a problem with pip after I upgraded
>> an installed version of python 3.6 on my Mint 18 system. Pip would not run
>> in my python 3.6 virtual environment. The fix was to use synaptic to install
>> python3-distutils. I thought everything was ok until I tried to run a old
>> script from a different VE using python 3.5 which could not import tkinter.
>>
>> I have 4 versions of python on this system:
>> system Python2 = 2.7.12 (default)
>> system Python3 = 3.5.2 (default)
>> a VE called env = 3.5.2
>> a Ve called env36 = 3.6.5
>>
>> This is the error I get trying to import tkinter in env, I also get the same
>> error if I try to import it in system python3.
>>
>> jfb at jims-mint18 ~ $ source /home/jfb/EVs/env/bin/activate
>> (env) jfb at jims-mint18 ~ $ python
>> Python 3.5.2 (default, Nov 23 2017, 16:37:01)
>> [GCC 5.4.0 20160609] on linux
>> Type "help", "copyright", "credits" or "license" for more information.
>>>>> import tkinter as tk
>> Traceback (most recent call last):
>>    File "/usr/lib/python3.5/tkinter/__init__.py", line 36, in <module>
>>      import _tkinter
>> ImportError: No module named '_tkinter'
>>
>> During handling of the above exception, another exception occurred:
>>
>> Traceback (most recent call last):
>>    File "<stdin>", line 1, in <module>
>>    File "/usr/lib/python3.5/tkinter/__init__.py", line 38, in <module>
>>      raise ImportError(str(msg) + ', please install the python3-tk package')
>> ImportError: No module named '_tkinter', please install the python3-tk
>> package
>>>>>
>>
>> If I go to synaptic and install the python3-tk it installs version 3.6.5 of
>> the package and I can still not import tkinter in env with python 3.5.2, but
>> I can in env36 with python 3.6.5.
>>
> 
> As I have not yet tried to play around with virtual environments, I
> may be about to do more harm than help, but I will plow ahead anyway!
> ~(:>))
> 
> My primitive understanding of installing Python versions that are
> different from the system Python version into a virtual environment,
> is that you have to install all dependencies you need from within that
> virtual environment you created.  If I am correct about this then your
> error messages suggest you need to install the tkinter stuff from
> within that virtual environment using that virtual environment's pip.
> Hopefully I am too far off from the truth here, but in any event, I
> hope this helps you in your problem!
> 

My understanding of VE's, based on some feedback from here, is you 
install install the python you want on the system then use it to install 
your VE. Then you install what ever you need to the VE. In my case I had 
a working VE based on python 3.5 then I received an upgrade to the 
python version 3.6 I had installed. After that I had problems with the 
3.5 VE that had been working.

Regards,  Jim



More information about the Tutor mailing list