Symbol not found: _FSPathMakeRef - python

Can't import Quartz package.
I have installed it with this command pip install pyobjc-framework-Quartz. Tried reinstalling python, also tried python -m pip install .... With python2 or sudo python3, everything works fine but python3 is giving me this error message every time I try importing Quartz
Python version - 3.10.4
Mac version - Big Sur 11.6.5
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import Quartz
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Quartz/__init__.py", line 6, in <module>
import AppKit
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/AppKit/__init__.py", line 10, in <module>
import Foundation
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/Foundation/__init__.py", line 9, in <module>
import CoreFoundation
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/CoreFoundation/__init__.py", line 9, in <module>
import objc
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/objc/__init__.py", line 6, in <module>
from . import _objc
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/objc/_objc.cpython-310-darwin.so, 2): Symbol not found: _FSPathMakeRef
Referenced from: /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/objc/_objc.cpython-310-darwin.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/objc/_objc.cpython-310-darwin.so

For investigation purposes, can you try :
cd /tmp
python3 -m venv venv
source venv/bin/activate
pip install pyobjc-framework-Quartz
python your-script.py
Can you try this to see if it works :
env -i /Library/Frameworks/Python.framework/Versions/3.10/bin/python3 my_script.py
You may have files only accessible by root, try to change ownership:
sudo chown -R $(id -u):$(id -g) /Library/Frameworks/Python.framework/Versions/3.10
and run env -i ... again.
If you run :
/Library/Frameworks/Python.framework/Versions/3.10/bin/python3 -c 'import sys;print(sys.path)'
sudo /Library/Frameworks/Python.framework/Versions/3.10/bin/python3 -c 'import sys;print(sys.path)'
Is there any difference between the two ?
Try following to see if it improves :
sudo /Library/Frameworks/Python.framework/Versions/3.10/bin/python3 -m pip install pyobjc-framework-Quartz
Try this to see if there is anything unusual :
/Library/Frameworks/Python.framework/Versions/3.10/bin/python3 -X importtest -v -c 'import Quartz'

You might need to try:
python3 -m pip install [...]
Hope this will hope.

Related

netplan not working after change default python

in ubuntu 18.04, when i change default python from python 3.6 to other version by this command:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1
or when i remove python 3.6 and install other version netplan apply not working and result this error:
File "/usr/sbin/netplan", line 20, in <module>
from netplan import Netplan
File "/usr/share/netplan/netplan/__init__.py", line 18, in <module>
from netplan.cli.core import Netplan
File "/usr/share/netplan/netplan/cli/core.py", line 24, in <module>
import netplan.cli.utils as utils
File "/usr/share/netplan/netplan/cli/utils.py", line 25, in <module>
import netifaces
ModuleNotFoundError: No module named 'netifaces'
and command pip install netifaces has some errors.
I faced the same issue before with vagrant. If you use update-alternatives to make python3 alias points to another version of Python, vagrant will not work. You cannot use update-alternatives to change the alias of Python3.
For some reason I lost my python configuration after an update made by my ubuntu server,solved by:
Checking if I could import the module so on CLI:
python
import python
After getting the same message I realize my python environment was falling to use the modules even when it all showed up as installed I went ahead and "upgrade" the python modules:
python pip install --upgrade pip
python pip install --upgrade netifaces
python pip install --upgrade "any module you need to use for your script"
And just like that modules were recognized updated and properly install.
tl;dr: Create a link netifaces.so to netifaces.cpython-36m-x86_64-linux-gnu.so in /usr/lib/python3/
In /usr/lib/python3/dist-packages/ is only a module for python3.6:
vagrant#ubuntu18.04:~$ find /usr/lib/python3/dist-packages/ -type f -name netifaces\*
/usr/lib/python3/dist-packages/netifaces.cpython-36m-x86_64-linux-gnu.so
That's why importing 'netifaces' failes for python3.8 while it works for python3.6:
vagrant#ubuntu18.04:~$ python3.6 -c 'import netifaces; print("works!")'
works!
vagrant#ubuntu18.04:~$ python3.8 -c 'import netifaces; print("works!")'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'netifaces'
One can link to it with a more unspecific name so python3.8 can find and use it:
vagrant#ubuntu18.04:~$ sudo ln -s /usr/lib/python3/dist-packages/netifaces.cpython-36m-x86_64-linux-gn
u.so /usr/lib/python3/dist-packages/netifaces.so
vagrant#ubuntu18.04:~$ python3.8 -c 'import netifaces; print("works!")'
works!
Hint: I had to do the same for apt_pkg.so → apt_pkg.cpython-36m-x86_64-linux-gnu.so

Running python script from terminal on MacOS requires

I have a cli with a few functions that i copy into /local/bin using:
sudo ln -s ~/code/project/scripts/sl /usr/local/bin/sl
If I activate the virtual env and do sl command_name service it works as expected.
But if try to run it from terminal I get:
user#MacBook-Pro-USER ~ % sl command_name service
Traceback (most recent call last):
File "/usr/local/bin/sl", line 4, in <module>
from sl_commands.sl import execute
File "/Users/user/code/project/scripts/sl_commands/sl.py", line 1, in <module>
import argh
ImportError: No module named argh
Running pip3 install argh results in:
user#MacBook-Pro-USER ~ % pip3 install argh
Requirement already satisfied: argh in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (0.26.2)
If I try the same on ubuntu the script executes correctly. How do i make it run on MacOS without activating a virtualenv?
The shebang needs to be #! /usr/bin/env python3 and not python. Since python2 is 'python' on MacOS

No module named '_ctypes'

I'm trying to install pyautogui, but pip keeps throwing errors. How to fix it? I've tried installing libffi library. Here is some code:
python3 -m pip install pyautogui
Defaulting to user installation because normal site-packages is not writeable
Collecting pyautogui
Using cached PyAutoGUI-0.9.50.tar.gz (57 kB)
ERROR: Command errored out with exit status 1:
command: /usr/local/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-sxm4ewnq/pyautogui/setup.py'"'"'; __file__='"'"'/tmp/pip-install-sxm4ewnq/pyautogui/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-85ugzov6
cwd: /tmp/pip-install-sxm4ewnq/pyautogui/
Complete output (11 lines):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.8/site-packages/setuptools/__init__.py", line 19, in <module>
from setuptools.dist import Distribution
File "/usr/local/lib/python3.8/site-packages/setuptools/dist.py", line 34, in <module>
from setuptools import windows_support
File "/usr/local/lib/python3.8/site-packages/setuptools/windows_support.py", line 2, in <module>
import ctypes
File "/usr/local/lib/python3.8/ctypes/__init__.py", line 7, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
That's from python REPL
>>> sys.path
['', '/home/walenty/apps/Python-3.8.5/Modules/_ctypes', '/usr/local/lib/python38.zip', '/usr/local/lib/python3.8', '/usr/local/lib/python3.8/lib-dynload', '/home/walenty/.local/lib/python3.8/site-packages', '/usr/local/lib/python3.8/site-packages']
>>> import _ctypes
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named '_ctypes'
Required
Install foreign function interface headers
sudo apt install libffi-dev
Reinstall Python
Substitute desired python version
Ubuntu
sudo add-apt-repository ppa:deadsnakes/ppa -y && sudo apt reinstall python3.9-distutils
MacOS
Use brew install python3.9 or port install python3.9 (I recommend port)
Windows
Use Microsoft Store
Specify project python version
Poetry
poetry env use 3.9
Virtual envs
virtualenv -p python3.9 myproject
etc...
okay, I've got it. This is the answer Python3: ImportError: No module named '_ctypes' when using Value from module multiprocessing
I cloned python3.10 from git and installed it from scratch.
As other answers say, you need to install libffi-dev. If you're using pyenv/virtualenv, also reinstall the base python version:
Install libffi
sudo apt-get install libffi-dev
Load the new libffi.so, as suggested here
sudo ldconfig
Reinstall the python version available to pyenv
pyenv install 3.9.12
Finally, create the fresh virtualenv
pyenv virtualenv 3.9.12 new_environment

ImportError: cannot import name '_gi' from partially initialized module 'gi' (most likely due to a circular import)

Looks like I have broken my python installation when I wanted to switch to python 3.8. Using Ubuntu 18.04. Trying to use the gi, gives the following error:
$ python
Python 3.8.1 (default, Dec 31 2019, 18:42:42)
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from gi.repository import GLib, Gio
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/gi/__init__.py", line 42, in <module>
from . import _gi
ImportError: cannot import name '_gi' from partially initialized module 'gi' (most likely due to a circular import) (/usr/lib/python3/dist-packages/gi/__init__.py)
Tried running update-alternatives for python, but it tells me there is only one python alternative configured (3.8).
Tried to reinstall python3-gi and python3.8. Still the same problem
I had the same issue. I linked python3 to python3.6, for me it was pointing to 3.8. That solved the issue.
cd /usr/bin/
rm python3
ln -s python3.6 python3
Thats all. Now my system started working fine.
Install gi for python 3.8: python3.8 -m pip install pgi
Then, instead of import gi use:
import pgi
pgi.install_as_gi()
from gi.repository import GLib, Gio
Alternatively, you can force install PyGObject for python 3.8:
sudo python3.8 -m pip install --ignore-installed PyGObject
which should allow one to from gi import ... as before.
For me the workaround was to create a symlink:
cd /usr/lib/python3/dist-packages/gi/
sudo ln -s _gi.so _gi.cpython-38-x86_64-linux-gnu.so
and it solved the problem for me.
I had the same problem on ubuntu 18 as python3 was referring to python3.9.
In order to solve it, I changed the alternative for python3:
sudo update-alternatives --config python3
There are 2 choices for the alternative python3 (providing /usr/bin/python3).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3.9 2 auto mode
1 /usr/bin/python3.6 1 manual mode
2 /usr/bin/python3.9 2 manual mode
By choosing number 1, now python3 points to python3.6 and everything works fine again
Found answer here https://bugzilla.redhat.com/show_bug.cgi?id=1709787:
The cause is - /usr/lib64/python3.8/site-packages/gi/_gi.cpython-38m-x86_64-linux-gnu.so has incorrect name:
sh-5.0# python3 -c 'from gi.repository import GLib'
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib64/python3.8/site-packages/gi/init.py", line 42, in
from . import _gi
ImportError: cannot import name '_gi' from 'gi' (/usr/lib64/python3.8/site-packages/gi/init.py)
sh-5.0# mv /usr/lib64/python3.8/site-packages/gi/_gi.cpython-38m-x86_64-linux-gnu.so /usr/lib64/python3.8/site-packages/gi/_gi.cpython-38-x86_64-linux-gnu.so
sh-5.0# python3 -c 'from gi.repository import GLib'
Note that since 3.8.0a4, the "m" is not supposed to be there. Is it somehow hardcoded?
sh-5.0# python3-config --extension-suffix
.cpython-38-x86_64-linux-gnu.so
in my case it was
$ sudo ln -s /usr/lib/python3/dist-packages/gi/_gi.cpython-35m-x86_64-linux-gnu.so /usr/lib/python3/dist-packages/gi/_gi.cpython-38-x86_64-linux-gnu.so
$ sudo ln -s /usr/lib/python3/dist-packages/gi/_gi_cairo.cpython-35m-x86_64-linux-gnu.so /usr/lib/python3/dist-packages/gi/_gi_cairo.cpython-38-x86_64-linux-gnu.so
The reason of this error is that this app can't find the matched Python version of _gi_cairo.cpython-(version)-x86_64-linux-gnu.so.
Normally, this unmatched situation is caused by some wrong mixed usage of different versions of Python.
So basically, you can try to switch your Python version ( to the default version of your OS). Or you can go to '/usr/lib/python3/dist-packages/gi' and create a new .so library file:
cp _gi_cairo.cpython-(old version)-x86_64-linux-gnu.so _gi_cairo.cpython-(new version)-x86_64-linux-gnu.so
or
ln -s _gi_cairo.cpython-(old version)-x86_64-linux-gnu.so _gi.so
Have same issue, can't load module from script folder. In my case work if i changing workdir for example (but only for inline command):
cd /tmp; python -c 'from gocd import Server'
echo $?
0
After copy script to /tmp, it's does't work
cp gocd.py /tmp
cd /tmp; python -c 'from gocd import Server'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/gocd.py", line 3, in <module>
from gocd import Server
ImportError: cannot import name 'Server' from partially initialized module 'gocd' (most likely due to a circular import) (/tmp/gocd.py)

Python wx via Homebrew

I'm having issues install Python wx on my Mac. Here's what I did:
brew install wxpython
which gave this Caveat:
Caveats
Python modules have been installed and Homebrew's site-packages is not
in your Python sys.path, so you will not be able to import the modules
this formula installed. If you plan to develop with these modules,
please run:
mkdir -p /Users/snowcrash/Library/Python/2.7/lib/python/site-packages
echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")'
>> /Users/snowcrash/Library/Python/2.7/lib/python/site-packages/homebrew.pth
So I ran the 2 commands from the Terminal as suggested:
mkdir -p /Users/snowcrash/Library/Python/2.7/lib/python/site-packages
>> echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")'
but when I try to import wx I am getting:
>>> import wx
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/wx-3.0-osx_cocoa/wx/__init__.py", line 45, in <module>
from wx._core import *
File "/usr/local/lib/python2.7/site-packages/wx-3.0-osx_cocoa/wx/_core.py", line 4, in <module>
import _core_
ImportError: dlopen(/usr/local/lib/python2.7/site-packages/wx-3.0-osx_cocoa/wx/_core_.so, 2): no suitable image found. Did find:
/usr/local/lib/python2.7/site-packages/wx-3.0-osx_cocoa/wx/_core_.so: mach-o, but wrong architecture
and this doesn't seem to help:
How do I install wxPython on Mac OS X?
Any suggestions?
Turned out I had to do this:
defaults write com.apple.versioner.python Prefer-32-Bit -bool no

Categories