Cant import pandas in Blender - python

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)

Related

Unable to use RDKit in Jupyter or iPython

I want to use RDKit in a Jupyter environment. However, after I followed the procedure outlined in this document.
After following the process, including getting the kernel for jupyter, I tried to access RDKit and play with it.
(rdkit-test) [user] ~ $ python
Python 3.7.9 (default, Aug 31 2020, 07:22:35)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable
'/Users/user/opt/anaconda3/envs/rdkit-test/bin/python'
>>> import rdkit
>>>
[6]+ Stopped python
Right from test anaconda environment rdkit-test, it seems like I can access rdkit and test with it.
Now, I try to access it via iPython:
(rdkit-test) [user] ~ $ ipython
Python 3.8.7 (v3.8.7:6503f05dd5, Dec 21 2020, 12:45:15)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.17.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import sys
In [2]: sys.executable
Out[2]: '/Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8'
In [3]: import rdkit
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-3-6b72bd8913ab> in <module>
----> 1 import rdkit
ModuleNotFoundError: No module named 'rdkit'
I can't seem to access rdkit. I can also see that I am not in the write environment, from my sys.executable command.
The same problem I see in a Jupyter notebook:
How do I fix this and use RDKit in Jupyter or iPython?
You should use !pip install kora. Then, use import kora.install.rdkit.

I can't import 'NSWorkspace' from 'AppKit'

I've got a problem when I try to import NSWorkspace an error appears:
No name 'NSWorkspace' in module 'AppKit'
Here is my code :
from AppKit import NSWorkspace
import time
activeAppName = ""
while True:
NewactiveAppName = NSWorkspace.sharedWorkspace().activeApplication()['NSApplicationName']
if activeAppName != NewactiveAppName:
activeAppName = NewactiveAppName
print (activeAppName)
time.sleep(10)
Python v3 does not import module AppKit with capital letters but requires lower ones:
import appkit
So, in my case, the original way works with only Python v2.
When I tried Python 3, it produced the following error:
Python 3.9.1 (default, Dec 17 2020, 03:41:37)
[Clang 12.0.0 (clang-1200.0.32.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import AppKit
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'AppKit'
>>>
When I use python 2.7 — it works fine:
WARNING: Python 2.7 is not recommended.
This version was included in macOS for compatibility with legacy software.
Future versions of macOS will not include Python 2.7. Instead, it is recommended using 'python3' from within Terminal scripts.
Python 2.7.16 (default, Mar 25 2021, 03:11:28)
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc- on darwin
Type "help", "copyright", "credits" or "license" for more information.
import AppKit
>>
NO ERROR.
Definitely, I have tried the recommended pip3 install AppKit PyObjC to no avail.
There is a recommendation that I didn't try.
So, I stick to use Python2 with the following script:
#!/usr/bin/python
import logging
logging.basicConfig(filename='/tmp/act_window.log', level=logging.INFO, format='%(asctime)s - %(
try:
from AppKit import NSWorkspace
activeAppName = NSWorkspace.sharedWorkspace().activeApplication()['NSApplicationName']
print(activeAppName)
logging.info(activeAppName)
except Exception as e:
logging.error("{0}".format(e))
print("Unknown")
————
UPDATE:
I have manually updated my AppKit library for python 3 and now use it in Python3-based script.
https://github.com/TinKurbatoff/appkit
2022 Update:
Per this post, pip3 install pyobjc made it possible to from AppKit import NSWorkspace (using Python 3.10.7)

Importerror: No module named time in python2.7.6 in ubuntu

I have a strange problem on python2.7.6 with Ubuntu :
my python 2.7.6 is installed but strangely time module is not working. my ubuntu version is 16.04
i tried installing python 2.7.16 as well but that didnt fixed the issue as
/usr/local/bin# python2.7
Python 2.7.6 (default, Jul 22 2019, 12:49:04)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named time
expected : import time should work
actual : ImportError: No module named time
How do i import time in python 2.7.6
output of :
: ls /usr/lib/python2.7/lib-dynload/
audioop.i386-linux-gnu.so _codecs_tw.i386-linux-gnu.so dl.i386-linux-gnu.so _lsprof.i386-linux-gnu.so Python-2.7.egg-info
audioop.x86_64-linux-gnu.so _codecs_tw.x86_64-linux-gnu.so _elementtree.i386-linux-gnu.so _lsprof.x86_64-linux-gnu.so readline.i386-linux-gnu.so
_bsddb.i386-linux-gnu.so crypt.i386-linux-gnu.so _elementtree.x86_64-linux-gnu.so mmap.i386-linux-gnu.so readline.x86_64-linux-gnu.so
_bsddb.x86_64-linux-gnu.so crypt.x86_64-linux-gnu.so fpectl.i386-linux-gnu.so mmap.x86_64-linux-gnu.so resource.i386-linux-gnu.so
bz2.i386-linux-gnu.so _csv.i386-linux-gnu.so fpectl.x86_64-linux-gnu.so _multibytecodec.i386-linux-gnu.so resource.x86_64-linux-gnu.so
bz2.x86_64-linux-gnu.so _csv.x86_64-linux-gnu.so future_builtins.i386-linux-gnu.so _multibytecodec.x86_64-linux-gnu.so _sqlite3.i386-linux-gnu.so
_codecs_cn.i386-linux-gnu.so _ctypes.i386-linux-gnu.so future_builtins.x86_64-linux-gnu.so _multiprocessing.i386-linux-gnu.so _sqlite3.x86_64-linux-gnu.so
_codecs_cn.x86_64-linux-gnu.so _ctypes_test.i386-linux-gnu.so _hashlib.i386-linux-gnu.so _multiprocessing.x86_64-linux-gnu.so _ssl.i386-linux-gnu.so
_codecs_hk.i386-linux-gnu.so _ctypes_test.x86_64-linux-gnu.so _hashlib.x86_64-linux-gnu.so nis.i386-linux-gnu.so _ssl.x86_64-linux-gnu.so
_codecs_hk.x86_64-linux-gnu.so _ctypes.x86_64-linux-gnu.so _hotshot.i386-linux-gnu.so nis.x86_64-linux-gnu.so termios.i386-linux-gnu.so
_codecs_iso2022.i386-linux-gnu.so _curses.i386-linux-gnu.so _hotshot.x86_64-linux-gnu.so ossaudiodev.i386-linux-gnu.so termios.x86_64-linux-gnu.so
_codecs_iso2022.x86_64-linux-gnu.so _curses_panel.i386-linux-gnu.so imageop.i386-linux-gnu.so ossaudiodev.x86_64-linux-gnu.so _testcapi.i386-linux-gnu.so
_codecs_jp.i386-linux-gnu.so _curses_panel.x86_64-linux-gnu.so _json.i386-linux-gnu.so parser.i386-linux-gnu.so _testcapi.x86_64-linux-gnu.so
_codecs_jp.x86_64-linux-gnu.so _curses.x86_64-linux-gnu.so _json.x86_64-linux-gnu.so parser.x86_64-linux-gnu.so
_codecs_kr.i386-linux-gnu.so dbm.i386-linux-gnu.so linuxaudiodev.i386-linux-gnu.so pyexpat.i386-linux-gnu.so
_codecs_kr.x86_64-linux-gnu.so dbm.x86_64-linux-gnu.so linuxaudiodev.x86_64-linux-gnu.so pyexpat.x86_64-linux-gnu.so
It seems time package is not install, you can try by installing time package using below command.
pip install times
or
sudo pip install times.
and then try?

How to edit python path

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)

Selenium installed in python, but still can't import module?

I'm using linux mint. I installed selenium using pip, and it finished with no problems. Then I ran python and tried to check that selenium works:
ethomas#ethomas-linux ~ $ python
Python 2.7.9 (default, May 19 2015, 13:47:37)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import selenium
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named selenium
then in python I did:
>>> import sys
>>> sys.executable
'/usr/local/bin/python'
>>> sys.path
['', '/usr/local/lib/python27.zip', '/usr/local/lib/python2.7', '/usr/local/lib/python2.7/plat-linux2', '/usr/local/lib/python2.7/lib-tk', '/usr/local/lib/python2.7/lib-old', '/usr/local/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/site-packages']
I ran $ locate selenium and it's all found in /usr/local/lib/python2.7/dist-packages/selenium. Yet I still can't import selenium in python. Anyone know what the problem might be? It may have something to do with the sys.path but I'm not sure.
I had installed python 2.7.9, while the default is 2.7.6 on my box, so it put it into usr/local/bin and was causing the error. Deleting it from usr/local/bin fixed the probelm.

Categories