{profile} 、. bash.profile,.profile.pysave中的Python $ PATH是否应该相同?

时间:2018-10-16 08:30:21

标签: python bash macos dependencies

在Mac OS X上,我安装了几个版本的Python以与afdk(字体修改模块)一起使用。建议我删除它们,然后重新开始。

查看.profile,.bash.profile和.profile.pysave文件,我发现已安装的所有以前版本均已记录。为了仅使用最新的Python版本,我是否应该通过删除旧版本来破解这些.bash文件,而仅保留当前Python版本的$ PATH?

$ echo $PATH
/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/adrianshome/bin/FDK/Tools/osx

谢谢, 阿德里安

因此,这是下面提到的.bash文件。

.profile:

##
# DELUXE-USR-LOCAL-BIN-INSERT
# (do not remove this comment)
##
echo $PATH | grep -q -s "/usr/local/bin"
if [ $? -eq 1 ] ; then
    PATH=$PATH:/usr/local/bin
    export PATH
fi

# Setting PATH for MacPython 2.5
# The orginal version is saved in .profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"

# Setting PATH for Python 3.4
# The orginal version is saved in .profile.pysave
# Initialization for FDK command line tools.Sun Oct 14 12:28:07 2018
FDK_EXE="/Users/adrianshome/bin/FDK/Tools/osx"
PATH=${PATH}:"/Users/adrianshome/bin/FDK/Tools/osx"
export PATH
export FDK_EXE

.profile.pysave:

##
# DELUXE-USR-LOCAL-BIN-INSERT
# (do not remove this comment)
##
echo $PATH | grep -q -s "/usr/local/bin"
if [ $? -eq 1 ] ; then
    PATH=$PATH:/usr/local/bin
    export PATH
fi

# Setting PATH for MacPython 2.5
# The orginal version is saved in .profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"
export PATH
# Initialization for FDK command line tools.Wed May 21 12:21:59 2008
FDK_EXE="/Users/adrianwi/bin/FDK/Tools/osx"
PATH=${PATH}:"/Users/adrianwi/bin/FDK/Tools/osx"

.bash.profile:

# Initialization for FDK command line tools.Fri Apr 10 14:12:30 2015

# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:${PATH}"

# Setting PATH for Python 3.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"

# Setting PATH for Python 2.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"

# Setting PATH for Python 2.7

这是安装Python3和AFDK模块的结果...

Last login: Sun Oct 14 12:50:11 on ttys001
Adrians-iMac-2:~ adrianshome$ pip3 install --user --upgrade afdko;
Collecting afdko
  Downloading https://files.pythonhosted.org/packages/b6/d2/0ba8ccfe42b0f88b0cc2819b73d93d4ad6240285a8d9a6a1570f39b1e613/afdko-2.8.2-py2.py3-none-macosx_10_6_intel.whl (2.4MB)
    100% |████████████████████████████████| 2.4MB 543kB/s 
Collecting ufoLib~=2.3.1 (from afdko)
  Downloading https://files.pythonhosted.org/packages/b7/72/e053c7f9adc52ee7f4ac163cebef4c8d39732a79a02f9abcfdcfbca35785/ufoLib-2.3.2-py2.py3-none-any.whl (109kB)
    100% |████████████████████████████████| 112kB 525kB/s 
Collecting ufonormalizer~=0.3.5 (from afdko)
  Downloading https://files.pythonhosted.org/packages/e6/f3/cdf8d7616cde052b07f3fb83eec34a4a534965df71968cbef9f3895a31c3/ufonormalizer-0.3.5-py2.py3-none-any.whl
Collecting defcon~=0.5.3 (from afdko)
  Downloading https://files.pythonhosted.org/packages/e5/e5/7491cd6b2f5ec7ef96804f31b8c5fd4d8030d2ff7f331fc2c179ff196bfa/defcon-0.5.3-py2.py3-none-any.whl (212kB)
    100% |████████████████████████████████| 215kB 1.6MB/s 
Collecting booleanOperations~=0.8.0 (from afdko)
  Downloading https://files.pythonhosted.org/packages/bd/98/4c43398f43b023803609ac4ab46b02f10936ba501c8e53e70ee8f21d794d/booleanOperations-0.8.0-py2.py3-none-any.whl
Collecting fontTools~=3.29.1 (from afdko)
  Downloading https://files.pythonhosted.org/packages/ab/68/a583423ac2ca5dd624ca4914ee97307b4b61a83dda5e0451f0242f628f58/fonttools-3.29.1-py2.py3-none-any.whl (612kB)
    100% |████████████████████████████████| 614kB 551kB/s 
Collecting psautohint==1.8.1 (from afdko)
  Downloading https://files.pythonhosted.org/packages/50/95/4583fcdb5cca5efe32c46dfa2bab95fcf2a99f43a8fd201971b5978d4705/psautohint-1.8.1-cp37-cp37m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (377kB)
    100% |████████████████████████████████| 378kB 486kB/s 
Collecting mutatorMath~=2.1.1 (from afdko)
  Downloading https://files.pythonhosted.org/packages/01/26/6d1583731da1d236f917b6618ac342ad435eb761750f934f1fc1bfd9ae84/MutatorMath-2.1.1-py2.py3-none-any.whl
Collecting fontMath~=0.4.7 (from afdko)
  Downloading https://files.pythonhosted.org/packages/33/b2/6e4d8fd1c0c82f42961dd4e901ecf819e490a64f2abb0a7bdf5082997a4f/fontMath-0.4.7-py2.py3-none-any.whl
Collecting fontPens~=0.1.0 (from afdko)
  Downloading https://files.pythonhosted.org/packages/76/11/0ad531d40c608eb3b798bb94607b10109b4e145142fe68eda40e92b84daf/fontPens-0.1.0-py2.py3-none-any.whl
Collecting pyclipper>=1.0.5 (from booleanOperations~=0.8.0->afdko)
  Downloading https://files.pythonhosted.org/packages/a0/2f/6a75e90bfb924118bd65cc16ccd23df53db697f0df7a4dfa79c6d64913fe/pyclipper-1.1.0.post1-cp37-cp37m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (275kB)
    100% |████████████████████████████████| 276kB 510kB/s 
Installing collected packages: fontTools, ufoLib, ufonormalizer, defcon, pyclipper, booleanOperations, psautohint, fontMath, mutatorMath, fontPens, afdko
  The scripts fonttools, pyftinspect, pyftmerge, pyftsubset and ttx are installed in '/Users/adrianshome/Library/Python/3.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  The script ufonormalizer is installed in '/Users/adrianshome/Library/Python/3.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  The script psautohint is installed in '/Users/adrianshome/Library/Python/3.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  The scripts autohint, buildcff2vf, buildmasterotfs, charplot, checkoutlinesufo, comparefamily, digiplot, fontplot, fontplot2, fontsetplot, hintplot, makeinstancesufo, makeotf, otc2otf, otf2otc, stemhist, ttfcomponentizer, ttxn and waterfallplot are installed in '/Users/adrianshome/Library/Python/3.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed afdko-2.8.2 booleanOperations-0.8.0 defcon-0.5.3 fontMath-0.4.7 fontPens-0.1.0 fontTools-3.29.1 mutatorMath-2.1.1 psautohint-1.8.1 pyclipper-1.1.0.post1 ufoLib-2.3.2 ufonormalizer-0.3.5
Adrians-iMac-2:~ adrianshome$ echo $PATH
/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/adrianshome/bin/FDK/Tools/osx
Adrians-iMac-2:~ adrianshome$ 
Adrians-iMac-2:~ adrianshome$ 

更新:11月2日

感谢很好的解释!我重新安装了Python3,并做了'pip3 install --user --upgrade afdko'来获取我需要的fonttools模块。创建了一个虚拟环境。然后再次运行我的代码例程,并显示关于“ site-packages”目录中未找到的模块的错误-即使它们在那里:

将ttx拖动到终端

粘贴代码以在带有dsig.ttx文件的桌面上创建“ Dsig fldr”。

输入了'-m'

将“ SassoInfProReg.ttf”拖到终端机

将“ dsig.ttx”拖到终端机

返回

有了这个结果(是否道歉代码不是全部等宽的?)...

(env37) Adrians-iMac-2:Dsig fldr adrianshome$ FLDR="${HOME}/Desktop/Dsig fldr"

(env37)Adrians-iMac-2:Dsig fldr adrianshome $ mkdir -p“ $ FLDR” (env37)Adrians-iMac-2:Dsig fldr adrianshome $ cd“ $ FLDR” (env37)Adrians-iMac-2:Dsig fldr adrianshome $ cat> dsig.ttx <

  

           00000001 00000000            紧急行动   (env37)Adrians-iMac-2:Dsig fldr adrianshome $ open。   (env37)Adrians-iMac-2:Dsig fldr adrianshome $ /库/Python/3.7/bin/ttx -m / Users / adrianshome / Desktop / Dsig \ fldr / SassoInfProReg.ttf / Users / adrianshome / Desktop / Dsig \ fldr / dsig.ttx

将“ / Users / adrianshome / Desktop / Dsig fldr / dsig.ttx”编译为“ / Users / adrianshome / Desktop / Dsig fldr / dsig.ttf” ... 解析“ DSIG”表... 错误:发生未处理的异常 追溯(最近一次通话):

文件“ /Users/adrianshome/Library/Python/3.7/lib/python/site-packages/fontTools/ttx.py”,第398行,位于主目录中     流程(工作,选项)

文件“ /Users/adrianshome/Library/Python/3.7/lib/python/site-packages/fontTools/ttx.py”,第372行,正在处理中     动作(输入,输出,选项)

文件“ /Users/adrianshome/Library/Python/3.7/lib/python/site-packages/fontTools/misc/loggingTools.py”,包装中的第375行     返回func(* args,** kwds)

ttCompile中的文件“ /Users/adrianshome/Library/Python/3.7/lib/python/site-packages/fontTools/ttx.py”,第290行     ttf.save(输出)

在保存的文件“ /Users/adrianshome/Library/Python/3.7/lib/python/site-packages/fontTools/ttLib/ttFont.py”中,第173行     writer_reordersTables = self._save(tmp)

文件_save中的文件“ /Users/adrianshome/Library/Python/3.7/lib/python/site-packages/fontTools/ttLib/ttFont.py”,第212行     self._writeTable(tag,writer,done,tableCache)

_writeTable中的文件“ /Users/adrianshome/Library/Python/3.7/lib/python/site-packages/fontTools/ttLib/ttFont.py”,第633行     tabledata = self.getTableData(tag)

getTableData中的文件“ /Users/adrianshome/Library/Python/3.7/lib/python/site-packages/fontTools/ttLib/ttFont.py”,第651行     返回self.tables [tag] .compile(self)

文件“ /Users/adrianshome/Library/Python/3.7/lib/python/site-packages/fontTools/ttLib/tables/D_S_I_G_.py”,第60行,正在编译     包装= sstruct.pack(DSIG_HeaderFormat,self)

文件“ /Users/adrianshome/Library/Python/3.7/lib/python/site-packages/fontTools/misc/sstruct.py”,第68行,已打包     值= obj [名称] KeyError:“ ulVersion” (env37)Adrians-iMac-2:Dsig fldr adrianshome $

1 个答案:

答案 0 :(得分:0)

这取决于您需要使用Python做什么,有时您的操作系统(在大多数情况下为Linux)附带了预安装的Python版本,这是许多内置功能的要求。通过删除或更改系统范围的版本,可能会对系统的运行产生负面影响。我不确定OSX是否会遇到这种情况,因为我经验有限。

如今,Python应用程序安装自己的本地python版本(虚拟环境)是一种相当普遍的做法,他们可以在其中安装自己的依赖项,而不会污染或负面影响它的系统范围。

如果您确定没有其他人使用它,则更改它可能是安全的,但也许先重命名目录,然后再查看并查看发生的情况(或中断),然后再将其删除。

关于您的相关配置文件:

  

.profile.pysave

无需修改它,它只是在安装python时创建的备份,因为它修改了现有的.profile,但会进行备份,以防您想回滚。

在.profile文件中,您可以将所有路径组合到一个变量中,然后将其导出。例如

PATH=${PATH}:/Library/Frameworks/Python.framework/Versions/Current/bin:/Users/adrianshome/bin/FDK/Tools/osx 
export PATH
  

.bash.profile

这有点棘手...您要在这里实现什么?

您只想使用最新版本的python还是要一次使用所有这三个版本?

我想您可能只想拥有一个最新版本的条目。像您那样同时使用这三种方法会互相冲突,并且不会具有预期的行为。

PATH的工作方式是按照指定顺序在目录中列出的目录中查找可执行文件。因此,如果您有这样的路径

PATH=/dir1:/dir2:/dir3

在这三个目录中的每个目录中,如果您每次在终端中键入“ python”,则都有一个名为“ python”的文件(假设其设置为可执行文件,并且您具有适当的权限),实际上您将调用/ dir1 / python,因为它是PATH中的第一个条目。

如您所见,如果您确实想使用/ dir3中的“ python”,那将导致问题。

如果您确实需要使用多个版本的python,我强烈建议您使用虚拟环境(google virtualenv)。这些将使您拥有隔离的python版本,并在需要时“激活”。

例如,我有两个程序,App1使用python 2.7和App2使用python 3.7,并且我有两个虚拟环境。我会像这样激活它们(请注意,这是一个示例,确切的路径将取决于创建它的位置)。

$ /Users/adrianshome/py2.7/bin/activate
$ App1

现在您的python 2.7是活动的,并且在路径中位于第一个位置,因此当您键入python时,您将获得python 2.7

类似地,您将执行以下操作来运行App2

$ deactivate (this will undo what you did previously)
$ /Users/adrianshome/py3.7/bin/activate
$ App2

我希望这会有所帮助!