Python$PATH在.profile中是否应该相同。bash.profile文件, .profile.pysave?

2024-04-25 19:10:18 发布

您现在位置:Python中文网/ 问答频道 /正文

在macosx上,我安装了一些Python版本,用于afdk(字体修改模块)。有人建议我把它们移走重新开始,我已经这样做了。在

正在查看。个人资料。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文件。在

.简介:

^{pr2}$

一。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--upgradeafdko”来获得我需要的fontcools模块。创建了一个虚拟环境。然后再次运行我的代码例程,错误地指出在“site packages”目录中找不到模块-即使它们在那里:

将ttx拖到终端

粘贴代码以在桌面上创建“Dsig fldr”,并使用数字签名.ttx把文件放进去。在

输入'-m'

拖SassoInfProReg.ttf公司'到终端

拖数字签名.ttx'到终端

返回

有了这个结果(抱歉,代码不全是等距的?)。。。在

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

(env37)Adrians-iMac-2:Dsig fldr阿德里安索姆$mkdir-p“$fldr” (env37)Adrians-iMac-2:Dsig fldr阿德里安索姆$cd“$fldr” (env37)Adrians-iMac-2:Dsig fldr阿德里安索姆$cat>;dsig.ttx和lt;

00000001 00000000 EOF (env37) Adrians-iMac-2:Dsig fldr adrianshome$ open . (env37) Adrians-iMac-2:Dsig fldr adrianshome$ /Library/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”/数字签名.ttx“收件人”/Users/adrianshome/Desktop/Dsig fldr/dsig.ttf公司"... 正在分析“DSIG”表。。。 错误:发生未处理的异常 回溯(最近一次呼叫):

File“/Users/adrianshome/lib/Python/3.7/lib/Python/site-packages/fontcools/ttx.py公司“,第398行,主要 流程(作业、选项)

File“/Users/adrianshome/lib/Python/3.7/lib/Python/site-packages/fontcools/ttx.py公司“,第372行,正在处理中 操作(输入、输出、选项)

File“/Users/adrianshome/lib/Python/3.7/lib/Python/site-packages/fontcools/misc/日志工具.py“,第375行,包装内 返回func(*args,**kwds)

File“/Users/adrianshome/lib/Python/3.7/lib/Python/site-packages/fontcools/ttx.py公司“,第290行,在ttCompile中 ttf.保存(输出)

File“/Users/adrianshome/lib/Python/3.7/lib/Python/site-packages/fontcools/ttLib/字体.py“,第173行,保存中 writer_reordersTables=自身.\u save(tmp)

File“/Users/adrianshome/lib/Python/3.7/lib/Python/site-packages/fontcools/ttLib/字体.py“,第212行,in\u save self.\u writeTable(标记、写入器、完成、tableCache)

File“/Users/adrianshome/lib/Python/3.7/lib/Python/site-packages/fontcools/ttLib/字体.py“,第633行,in\u writeTable 表格数据=self.getTableData(标签)

File“/Users/adrianshome/lib/Python/3.7/lib/Python/site-packages/fontcools/ttLib/字体.py,第651行,在getTableData中 返回self.tables表格[标记].compile(self)

文件“/Users/adrianshome/Library/Python/3.7/lib/Python/site packages/fontcools/ttLib/tables/D_S_I_G_y.py”,第60行,编译中 打包=结构包(DSIG\U HeaderFormat,自我)

File“/Users/adrianshome/lib/Python/3.7/lib/Python/site-packages/fontcools/misc/结构副本“,第68行,包装内 值=对象[名称] KeyError:'ulVersion' (env37)Adrians-iMac-2:Dsig fldr阿德里安索姆$


Tags: pathbinlibpackageslibraryframeworkversionsusers
1条回答
网友
1楼 · 发布于 2024-04-25 19:10:18

这取决于您需要使用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的工作方式是按照指定的顺序在列出的目录中查找可执行文件。所以如果你有这样一条路

^{pr2}$

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

如您所见,如果您真的想使用/dir3中的“python”,这将导致问题。在

如果您确实需要使用python的多个版本,我强烈建议您使用虚拟环境(googlevirtualenv)。这将允许您在需要时“激活”python的独立版本。在

例如我有两个程序,App1使用python2.7,App2使用python3.7,我有两个虚拟环境。我会像这样激活它们(注意这是一个例子,确切的路径将取决于您创建它的位置)。在

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

现在您的python2.7是活动的,并且是路径中的第一个,所以当您键入python时,您将得到python2.7

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

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

我希望这有帮助!在

相关问题 更多 >