首页 > swift REPL无法正常使用

swift REPL无法正常使用

刚开始接触swift,想着在mac上用 swift REPL,敲一些简单的语法,不需要一句简单的print用xcode还要编译。结果按照网上和书本的相关教程,不管怎样都无法正常使用swift REPL,尝试过stack overflow上的一些解决方案,始终无法解决,求使用过的有经验者帮帮忙。
osx version:10.10.5
xcode version:7.2.1

先转换xcode目录

sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

再运行xcrun swift或者swift

$ xcrun swift
Welcome to Apple Swift version 2.1.1 (swiftlang-700.1.101.15 clang-700.1.81). Type :help for assistance.
warning: Swift error in module repl_swift: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module dyld: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module CoreFoundation: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libedit.3.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libz.1.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libpanel.5.4.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libncurses.5.4.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libSystem.B.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libauto.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libDiagnosticMessagesClient.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libicucore.A.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libobjc.A.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libcache.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libcommonCrypto.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libcompiler_rt.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libcopyfile.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libcorecrypto.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libdispatch.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libdyld.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libkeymgr.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module liblaunch.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libmacho.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libquarantine.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libremovefile.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libsystem_asl.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libsystem_blocks.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libsystem_c.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libsystem_configuration.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libsystem_coreservices.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libsystem_coretls.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libsystem_dnssd.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libsystem_info.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libsystem_kernel.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libsystem_m.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libsystem_malloc.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libsystem_network.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libsystem_networkextension.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libsystem_notify.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libsystem_platform.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libsystem_pthread.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libsystem_sandbox.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libsystem_secinit.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libsystem_stats.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libsystem_trace.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libunc.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libunwind.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libxpc.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libc++.1.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libc++abi.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libswiftCore.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libswiftDarwin.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module Foundation: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libextension.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libarchive.2.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libxml2.2.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module CFNetwork: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module SystemConfiguration: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module Security: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module CoreServices: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module liblangid.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module IOKit: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libCRFSuite.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libbz2.1.0.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module liblzma.5.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libbsm.0.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libsqlite3.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libkxld.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libxar.1.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libpam.2.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libOpenScriptingUtil.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module FSEvents: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module CarbonCore: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module Metadata: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module OSServices: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module SearchKit: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module AE: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module LaunchServices: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module DictionaryServices: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module DiskArbitration: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module NetFS: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module NetAuth: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module loginsupport: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module DataDetectorsCore: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module TCC: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libmecabra.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module ApplicationServices: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module CoreGraphics: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module CoreText: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module ImageIO: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module ATS: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module ColorSync: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module HIServices: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module LangAnalysis: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module PrintCore: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module QD: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module SpeechSynthesis: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module IOSurface: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module Accelerate: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module MultitouchSupport: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module vImage: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module vecLib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libvDSP.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libvMisc.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libLAPACK.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libBLAS.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libLinearAlgebra.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libFontParser.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libFontRegistry.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module AppleVPA: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module AppleJPEG: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libJPEG.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libTIFF.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libPng.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libGIF.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libJP2.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libRadiance.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module OpenGL: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module CoreVideo: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libGLU.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libGFXShared.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libGL.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libGLImage.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libCVMSPluginSupport.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libCoreVMClient.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libcups.2.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module Kerberos: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module GSS: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libresolv.9.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libiconv.2.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module Heimdal: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libheimdal-asn1.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module OpenDirectory: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module CommonAuth: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module CFOpenDirectory: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module SecurityFoundation: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module CoreAudio: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module AudioToolbox: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module LanguageModeling: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libcmph.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module CoreData: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module ServiceManagement: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

warning: Swift error in module libxslt.1.dylib: 
    Error creating module Swift AST context: couldn't get a ClangImporter
Debug info from this module will be unavailable in the debugger.

error: Error creating target Swift AST context: (null)

配置完之后,无法使用,在google搜索了一下,在stack overflow上看到个答案:
stack overflow答案 按照这个答案中的提示将文件夹转换成了系统自带的swift之后,可以进入xcrun swift界面,但是任然无法使用

sudo xcode-select --switch /Library/Developer/CommandLineTools
~ ZH$ xcode-select -p
/Library/Developer/CommandLineTools
~ ZH$ xcrun swift
Welcome to Swift version 1.2. Type :help for assistance.
  1> print("hello world")
Error in auto-import:
failed to get module 'Swift' from AST context
  1>  

网上找来找去也就这两种配置,在我mac上都无法使用,求解决方法。


你好。同为新手,我也遇到了这个问题,暂时也没找到解决办法,请问你已经解决了吗


我的问题,更新版本便可解决,至于具体原因在哪儿,我就不清楚了,因为没时间去深究,能用了就好。所以有遇到和我问题类似情况的朋友们,不妨先升级,再试试看,如果不行再找其他方案。

【热门文章】
【热门文章】