我有一个大脚本,我需要编译成一个使用pyteomics模块的.exe可执行文件。安装脚本“build_script.py”(通常命名为“setup.py”)如下所示:
import sys
from os import environ
from cx_Freeze import setup, Executable
# Set the TCL and TK library explicitly (it seems like the python 3.6 causes
# errors otherwise):
environ['TCL_LIBRARY'] = r'C:\ProgramData\Anaconda3\tcl\tcl8.6'
environ['TK_LIBRARY'] = r'C:\ProgramData\Anaconda3\tcl\tk8.6'
#Inclusion of dll files to fix tkinter import:
include_files = [r'C:\ProgramData\Anaconda3\DLLs\tcl86t.dll', \
r'C:\ProgramData\Anaconda3\DLLs\tk86t.dll']
#Inclusion of modules that need to be explicitly imported for some reason:
packages = ['pyteomics']
#Dependencies that are not implicitly detected:
build_exe_options = {'includes': [],
'include_files': include_files,
'packages': packages}
# GUI applications require a different base on Windows (the default is for a
# console application).
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
setup( name = 'Davidek beta 1.1.1',
version = '1.1.1',
options = {'build_exe': build_exe_options},
executables = [Executable('Davidek.py', base=base)])
正如您所看到的,我尝试将pyteomics显式导入为包,但它仍然提供相同的错误消息:
(C:\ProgramData\Anaconda3) C:\Users\Max\Scilifelab\Projects\Master thesis\Davidek\Code>python build_script.py build
running build
running build_exe
Traceback (most recent call last):
File "build_script.py", line 39, in <module>
executables = [Executable('Davidek.py', base=base)])
File "C:\ProgramData\Anaconda3\lib\site-packages\cx_Freeze\dist.py", line 349, in setup
distutils.core.setup(**attrs)
File "C:\ProgramData\Anaconda3\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\ProgramData\Anaconda3\lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)
File "C:\ProgramData\Anaconda3\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\ProgramData\Anaconda3\lib\distutils\command\build.py", line 135, in run
self.run_command(cmd_name)
File "C:\ProgramData\Anaconda3\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\ProgramData\Anaconda3\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\ProgramData\Anaconda3\lib\site-packages\cx_Freeze\dist.py", line 219, in run
freezer.Freeze()
File "C:\ProgramData\Anaconda3\lib\site-packages\cx_Freeze\freezer.py", line 621, in Freeze
self.finder = self._GetModuleFinder()
File "C:\ProgramData\Anaconda3\lib\site-packages\cx_Freeze\freezer.py", line 340, in _GetModuleFinder
finder.IncludePackage(name)
File "C:\ProgramData\Anaconda3\lib\site-packages\cx_Freeze\finder.py", line 653, in IncludePackage
module = self._ImportModule(name, deferredImports)
File "C:\ProgramData\Anaconda3\lib\site-packages\cx_Freeze\finder.py", line 350, in _ImportModule
raise ImportError("No module named %r" % name)
ImportError: No module named 'pyteomics'
我在64位Windows 10上使用Python 3.6.0。
根据要求编辑:
以下是导入pyteomics的具体脚本:
from pyteomics import mass
#Carbon isotopic label weight:
Cmass = 13.0033548378 - 12
Nmass = 15.0001088982 - 14.0030740048
#IAA added weight:
IAAmass = 57.02146
def calculate_mass(sequence, charge, ionType, IAA):
""" Calculates and returns the monoisotopic mass of an ion.
>>> calculate_mass('PEPTIDECK', 1, 'y', 1)
1088.4928482921898
>>> calculate_mass('PEPTIDECK', 1, 'b', 1)
1070.48228360849
>>> calculate_mass('PEPTIDECK', 1, 'y', 0)
1031.4713882921899
>>> calculate_mass('PEPTIDECK', 2, 'y', 1)
544.7500623794799
"""
monoisotopicMass = mass.calculate_mass(sequence, charge=charge, ion_type=ionType)
if IAA:
monoisotopicMass += IAAmass*sequence.count('C')/charge
return monoisotopicMass
def calculate_heavyShift(sequence, labels):
""" Calculates and returns the mass shift of a heavy peptide given the sequence.
>>> calculate_heavyShift("PEPTIDECK", 'K:0C2N, R:0C2N')
1.9940697868000008
"""
#Count number of K and R in sequence:
Knum = sequence.count('K')
Rnum = sequence.count('R')
#Calculate mass shift:
Kmass = int(labels.split(',')[0].split(':')[1][0])*Cmass + int(labels.split(',')[0].split(':')[1][2])*Nmass
Rmass= int(labels.split(' ')[1].split(':')[1][0])*Cmass + int(labels.split(' ')[1].split(':')[1][2])*Nmass
return Kmass*Knum + Rmass*Rnum
def calculate_fragmentPeakCluster(sequence, charge, IAA, maxClusterPeaks, labels, ionType, includedPeaks):
""" Calculates and returns a dictionary of the peak cluster of a certain fragment.
>>> calculate_fragmentPeakCluster('PEPTIDECK', 1, 1, 3, 'K:0C2N, R:0C2N', 'y', ['l0','l1','l2','h0'])=={'y9 l1+': 1089.49620312999, 'y9 l0+': 1088.4928482921898, 'y9 l2+': 1090.4995579677898, 'y9 h0+': 1090.48691807899}
True
"""
monoisotopicMass = calculate_mass(sequence, charge, ionType, IAA)
heavyShift = calculate_heavyShift(sequence, labels)
fragmentNumber = len(sequence)
fragmentCluster = {}
lightID = ' l'
#b-fragments are the same mass whether from heavy or light origins:
if ionType=='b':
lightID=' '
#Parse through peaks in isotopic order:
for peakNumber in range(maxClusterPeaks):
#Calculate light peak m/z:
if 'l'+str(peakNumber) in includedPeaks:
lightPeakMass = monoisotopicMass + peakNumber*Cmass/charge
fragmentCluster[ionType + str(fragmentNumber) + lightID +str(peakNumber) + '+'*charge] = lightPeakMass
#Calculate heavy peak m/z. Not for 'b'-ions
if not ionType=='b':
if 'h'+str(peakNumber) in includedPeaks:
heavyPeakMass = lightPeakMass + heavyShift/charge
fragmentCluster[ionType + str(fragmentNumber) + ' h' +str(peakNumber) + '+'*charge] = heavyPeakMass
return fragmentCluster
def calculate_precursorPeakCluster(sequence, charge, maxClusterPeaks, labels, IAA=False):
""" Calculate and returns the m/z of the precursor's isotope cluster.
#No IAA/CAA:
>>> calculate_precursorPeakCluster("PEPTIDECK", 1, 3, 'K:0C2N, R:0C2N', IAA=False)=={'l0': 1031.4713882921899, 'l1': 1032.47474312999, 'h1': 1034.46881291679, 'h2': 1035.47216775459, 'l2': 1033.4780979677898, 'h0': 1033.46545807899}
True
#With IAA/CAA:
>>> calculate_precursorPeakCluster("PEPTIDECK", 1, 3, 'K:0C2N, R:0C2N', IAA=True)=={'l0': 1088.4928482921898, 'l1': 1089.49620312999, 'h1': 1091.49027291679, 'h2': 1092.4936277545899, 'l2': 1090.4995579677898, 'h0': 1090.48691807899}
True
#With IAA/CAA and charge 2:
>>> calculate_precursorPeakCluster("PEPTIDECK", 2, 3, 'K:0C2N, R:0C2N', IAA=True)=={'l0': 544.7500623794799, 'l1': 545.25173979838, 'h1': 546.24877469178, 'h2': 546.7504521106799, 'l2': 545.7534172172799, 'h0': 545.74709727288}
True
"""
precursorCluster = {}
#Calculate the monoisotopic mass over charge:
monoisotopicMass = calculate_mass(sequence, charge, 'y', IAA)
#Calculate peak mass over charges for every peaknumber:
for peakNumber in range(maxClusterPeaks):
#Calculate light peak m/z:
lightPeakMass = monoisotopicMass + peakNumber*Cmass/charge
precursorCluster['l'+str(peakNumber)] = lightPeakMass
#Calculate heavy peak m/z
heavyShift = calculate_heavyShift(sequence, labels)
heavyPeakMass = lightPeakMass + heavyShift/charge
precursorCluster['h'+str(peakNumber)] = heavyPeakMass
return precursorCluster
if __name__ == '__main__':
import doctest
doctest.testmod()
pyteomics的树结构如下所示:
C:.
| achrom.py
| auxiliary.py
| electrochem.py
| fasta.py
| featurexml.py
| mgf.py
| mzid.py
| mzml.py
| mzxml.py
| parser.py
| pepxml.py
| pylab_aux.py
| tandem.py
| xml.py
|
+---mass
| | mass.py
| | unimod.py
| | __init__.py
| |
| \---__pycache__
| mass.cpython-36.pyc
| unimod.cpython-36.pyc
| __init__.cpython-36.pyc
|
+---openms
| | featurexml.py
| | trafoxml.py
| | __init__.py
| |
| \---__pycache__
| featurexml.cpython-36.pyc
| trafoxml.cpython-36.pyc
| __init__.cpython-36.pyc
|
\---__pycache__
achrom.cpython-36.pyc
auxiliary.cpython-36.pyc
electrochem.cpython-36.pyc
fasta.cpython-36.pyc
featurexml.cpython-36.pyc
mgf.cpython-36.pyc
mzid.cpython-36.pyc
mzml.cpython-36.pyc
mzxml.cpython-36.pyc
parser.cpython-36.pyc
pepxml.cpython-36.pyc
pylab_aux.cpython-36.pyc
tandem.cpython-36.pyc
xml.cpython-36.pyc