I use both python3.5.3 (default) and python 3.6.5 that I installed on raspberry pi.
The path for each version is as below.
I'd like to add the path, /usr/lib/python3/dist-packages, under python3.6 and remove it from python3.5. How could I do that?
user#raspberrypi:~ $ python3.6
Python 3.6.5 (default, Apr 5 2018, 18:01:08)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> import pprint
>>> pprint.pprint(sys.path)
['',
'/usr/local/lib/python36.zip',
'/usr/local/lib/python3.6',
'/usr/local/lib/python3.6/lib-dynload',
'/usr/local/lib/python3.6/site-packages']
user#raspberrypi:~ $ python3.5
Python 3.5.3 (default, Jan 19 2017, 14:11:04)
[GCC 6.3.0 20170124] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> import pprint
>>> pprint.pprint(sys.path)
['',
'/usr/lib/python35.zip',
'/usr/lib/python3.5',
'/usr/lib/python3.5/plat-arm-linux-gnueabihf',
'/usr/lib/python3.5/lib-dynload',
'/usr/local/lib/python3.5/dist-packages',
'/usr/lib/python3/dist-packages']
As each version of Python seems to maintain its own environment (and path) how's about adding this to the beginning of your program:
import sys
myPath='/usr/lib/python3/dist-packages' # or whatever else you want it to be
if '3.6' in sys.version and not myPath in sys.path:
sys.path.append(myPath)
elif '3.5' in sys.version and myPath in sys.path:
sys.path.remove(myPath)
Related
I am trying to import pandas in blender but it's not finding the module.
I have checked that Blender has the correct paths and looks like it is.
This is my output in blender:
>>> print(sys.path)
['/usr/share/blender/2.93/scripts/startup', '/usr/share/blender/2.93/scripts/modules', '/usr/lib/python39.zip', '/usr/lib/python3.9', '/usr/lib/python3.9/lib-dynload', '/usr/lib/python3.9/site-packages', '/usr/lib/python3.9/site-packages/evtk-2.0.0-py3.9.egg', '/usr/share/blender/2.93/scripts/freestyle/modules', '/usr/share/blender/2.93/scripts/addons/modules', '/home/jjcasmar/.config/blender/2.93/scripts/addons/modules', '/usr/share/blender/2.93/scripts/addons', '/home/jjcasmar/.config/blender/2.93/scripts/addons', '/usr/share/blender/2.93/scripts/addons_contrib']
>>> print(sys.version)
3.9.7 (default, Aug 31 2021, 13:28:12)
[GCC 11.1.0]
>>> print(sys.path)
['/usr/share/blender/2.93/scripts/startup', '/usr/share/blender/2.93/scripts/modules', '/usr/lib/python39.zip', '/usr/lib/python3.9', '/usr/lib/python3.9/lib-dynload', '/usr/lib/python3.9/site-packages', '/usr/lib/python3.9/site-packages/evtk-2.0.0-py3.9.egg', '/usr/share/blender/2.93/scripts/freestyle/modules', '/usr/share/blender/2.93/scripts/addons/modules', '/home/jjcasmar/.config/blender/2.93/scripts/addons/modules', '/usr/share/blender/2.93/scripts/addons', '/home/jjcasmar/.config/blender/2.93/scripts/addons', '/usr/share/blender/2.93/scripts/addons_contrib']
>>> import pandas
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
ModuleNotFoundError: No module named 'pandas'
And this is the output if I just launch a python environment from my virtual terminal
[jjcasmar#archlinux ~]$ python
Python 3.9.7 (default, Aug 31 2021, 13:28:12)
[GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.version)
3.9.7 (default, Aug 31 2021, 13:28:12)
[GCC 11.1.0]
>>> print(sys.path)
['', '/usr/lib/python39.zip', '/usr/lib/python3.9', '/usr/lib/python3.9/lib-dynload', '/home/jjcasmar/.local/lib/python3.9/site-packages', '/usr/lib/python3.9/site-packages', '/usr/lib/python3.9/site-packages/evtk-2.0.0-py3.9.egg']
>>> import pandas as pd
>>>
My blender environment has the correct paths and the versions are the same, but it fails to import pandas. What is wrong here?
Have you installed the lib? Try pip install pandas
Have you activated your virtual environment?
Maybe you could try to install pandas directly from the blender's pip environment ?
Open a python interactive console in blender then:
import pip
pip.main(['install','pandas==1.4.0'])
Then as you did you can try to import pandas to see if it works:
import pandas as pd
(On my side i tested on MacosX only but it works)
See below:
$ python3
Python 3.6.9 (default, Apr 18 2020, 01:56:04)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path.abspath('~/gitlab')
'/home/swift/gitlab/swift_test_code/swift/core/~/gitlab'
>>> os.path.expanduser('~/gitlab')
'/home/swift/gitlab'
Does anyone know why abspath doesn't expand ~ as the home directory? It's tricky to call expand before calling abspath.
When I want to import a module into Python under the current user the import works OK. But when I want to import the same module as a root user, all of the sudden the module is not found.
Here is the the proof:
root#raspberrypi:/home/pi/Programs# whoami
root
root#raspberrypi:/home/pi/Programs# python3
Python 3.7.3 (default, Apr 3 2019, 05:39:12)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import paho.mqtt.client as paho
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'paho'
>>>
root#raspberrypi:/home/pi/Programs# su pi
pi#raspberrypi:~/Programs $ python3
Python 3.7.3 (default, Apr 3 2019, 05:39:12)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import paho.mqtt.client as paho
>>>
pi#raspberrypi:~/Programs $
I have already tried to modify the .bashrc as root by adding the PYTHONPATH to the module, but without success. What am I missing?
This is the output as a regular user:
pi#raspberrypi:~/Programs $ whoami
pi
pi#raspberrypi:~/Programs $ python3 -c 'import sys; print(sys.path)'
['', '/home/pi/Programs', '/usr/local/lib/python3.7/dist-packages/Adafruit_PCA9685', '/usr/local/lib/python3.7/dist-packages/Adafruit_GPIO', '/home/pi/.local/lib/python3.7/site-packages/paho', '/home/pi/Programs/usr/local/lib/python3.7/site-packages/paho', '/usr/lib/python37.zip', '/usr/lib/python3.7', '/usr/lib/python3.7/lib-dynload', '/home/pi/.local/lib/python3.7/site-packages', '/usr/local/lib/python3.7/dist-packages', '/usr/local/lib/python3.7/dist-packages/rpi_ws281x-1.0.0-py3.7-linux-armv7l.egg', '/usr/lib/python3/dist-packages']
And this is the output as root:
pi#raspberrypi:~/Programs $ su
root#raspberrypi:/home/pi/Programs# python3 -c 'import sys; print(sys.path)'
['', '/home/pi/Programs', '/usr/local/lib/python3.7/dist-packages/Adafruit_PCA9685', '/usr/local/lib/python3.7/dist-packages/Adafruit_GPIO', '/home/pi/.local/lib/python3.7/site-packages/paho', '/home/pi/Programs/usr/local/lib/python3.7/site-packages/paho', '/usr/lib/python37.zip', '/usr/lib/python3.7', '/usr/lib/python3.7/lib-dynload', '/usr/local/lib/python3.7/dist-packages', '/usr/local/lib/python3.7/dist-packages/rpi_ws281x-1.0.0-py3.7-linux-armv7l.egg', '/usr/lib/python3/dist-packages']
It seems in both versions path to paho is the same !???
I am trying to start a vagrant vm and provision it using its ansible provisioner;
config.vm.provision "ansible" do |ansible|
ansible.limit = "all"
ansible.compatibility_mode = "2.0"
ansible.playbook = "ansible/install.yml"
end
the box is ubuntu/xenial64
Provisioning fails as follows:
==> default: Running provisioner: ansible...
default: Running ansible-playbook...
ImportError: No module named site
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
Host is Ubuntu 16.04.05 with ansible 2.7.0
I even tried to run a shell provisioner that installs python-minimal on the guest before executing ansible, but with no luck.
edit: in the mean time, on my controller:
/home/pkara/Desktop
$ python
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import site
>>>
/home/pkara/Desktop
$ python3
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 site
>>>
I downloaded the tar file for libsvm, navigated to the python directory and ran the make command. This words and when I run python inside that same directory,
import svm
works just fine. But not in any other directory. What can I do to make this library accessible from any where? I know it has some thing to do with copying the path some where, but not sure since I'm a newbie at linux.
what linux distro are you on? on my Ubunto I just:
$ sudo apt-get install python-libsvm
...
$ python
Python 2.7.3 (default, Sep 26 2013, 20:03:06)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import svm
>>>
$ cd /tmp
$ python
Python 2.7.3 (default, Sep 26 2013, 20:03:06)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import svm
>>>