2

I am facing problems installing pyobjc on my mac.
Basically I have to install pyobjc on a new Mac System in the system default python. I have so far tried easy_install, pip and downloading the pkg file and installing. All give me a error in different ways. Some give me a error saying certain safari files are missing other cant due to some permission being denied even though I am running them through sudo su.
I then found a fix.

    pip install pyobjc --user

This worked and I could access all the modules I required, but then if I try running python through sudo, I cant access those modules.
Can anyone suggest a fix for this.

NOTE: I don't mind a different method to install also. Also I have not tried brew due to some previous difficulties with it.

NOTE 2: I need to be able to access those modules using all users on the computer, the root user and me(the non-root user)

ShdwKnght333
  • 300
  • 4
  • 23
  • one idea is to check your path and python,sudo user might have installed and pointed to different path – DevD Feb 27 '17 at 04:50
  • There is just one python installed on my computer. Just the system python that comes with the machine. It is a new machine freshly installed mac. I dont know how it might install into a different path? Or am I missing something here? – ShdwKnght333 Feb 27 '17 at 05:06

2 Answers2

2

i had to (temporarily) move (using sudo) /Library/Python/2.7/site-packages/Extras.pth to another name before I could install the current pyobjc.

This is what works for me:

sudo mv /Library/Python/2.7/site-packages/Extras.pth /Library/Python/2.7/site-packages/Extras.pth_orig
pip install --upgrade pyobjc
sudo mv /Library/Python/2.7/site-packages/Extras.pth_orig /Library/Python/2.7/site-packages/Extras.pth

It appears that something in the .pth file interferes with the install, but does not impede running pyobjc.

cco
  • 5,873
  • 1
  • 16
  • 21
1

but then if I try running python through sudo, I cant access those modules.

Because sudo python basically means run python as some other user (root by default). That user may have a different set of environment variables, including $PATH.

Some of linux distributions use older Python version for root user,like centos.If the Python verison you're running with sudo isn't correct,you can't access those modules installed by pip.

So in my opinion,if you didn't get permission issues,you don't need to use sudo ,using sudo might bring unexpected mistakes(most environment variables issues),maybe chown or chmod can fix those issues.

So here are my plans:

Plan A: The best way is to try to use virtualenv.

Plan B: Install modules without sudo command,if got permission errors(not very common),try --user .

Install to the Python user install directory for your platform. Typically ~/.local/, or %APPDATA%Python on Windows.

In most cases,you should modify your PYTHONPATH.See details from How do I access packages installed by pip --user.

Plan C: All related commands are executed with sudo.sudo pip install (all modules) and sudo python script.py.Not a good idea.

Community
  • 1
  • 1
McGrady
  • 10,869
  • 13
  • 47
  • 69
  • I got errors when installing using sudo, so I used --user. But I need to be able to access the modules through all the users. – ShdwKnght333 Feb 27 '17 at 05:34
  • How would I go through using virtualenv. I have not used that before. – ShdwKnght333 Feb 27 '17 at 05:34
  • @ShdwKnght333 Access the modules,have a look at [this question](http://stackoverflow.com/questions/38112756/how-do-i-access-packages-installed-by-pip-user).And you can also read [virtualenv doc](https://virtualenv.pypa.io/en/stable/). – McGrady Feb 27 '17 at 05:37