Error when trying to run Swift from terminal - xcode

After entering
~ sudo xcode-select -switch /Applications/Xcode6-Beta3.app/Contents/Developer
and then
~ xcrun swift
I get an error
ImportError: No module named site
Assertion failed: (err == 0), function ~Mutex, file /SourceCache/lldb/lldb-320.4.106.2/source/Host/common/Mutex.cpp, line 246.
Abort trap: 6
What am I missing? Several tutorials online give this code, so I'm guessing it must be some sort of setup issue.

I had a similar error and resolved it by removing the entry to my 3rd-party Python distribution (Enthought Canopy, in my case) from the PATH environment variable. This was a manual hack in my Terminal session and is good for only that session but it was as simple as this:
~ [1]$ swift
ImportError: No module named site
~ [2]$ echo $PATH
/Users/tdiller/Library/Enthought/Canopy_64bit/User/bin:/usr/local/git/bin:~/bin:/Library/Frameworks/Python.framework/Versions/Current/bin:/opt/local/bin:/opt/local/sbin:/usr/local/texlive/2012/bin/universal-darwin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/usr/local/go/bin
~ [3]$ PATH=PATH=/usr/local/git/bin:~/bin:/Library/Frameworks/Python.framework/Versions/Current/bin:/opt/local/bin:/opt/local/sbin:/usr/local/texlive/2012/bin/universal-darwin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/usr/local/go/bin
~ [4]$ export PATH
~ [5]$ swift
Welcome to Swift version 1.2. Type :help for assistance.
1>
I'm not sure what in Canopy-64bit/User/bin/ intereferes with Swift, but removing that item on the path seems to do the trick if you want to use the Swift REPL. There doesn't seem to be a problem with the EPD-style entry (/Library/Frameworks/Python.framework...).
Of course, Canopy won't work from this Terminal session, but I'm not sure it's important to have Python REPL and Swift REPL working in the same session.

It should be
$ xcode-select -switch /Applications/Xcode6-Beta3.app/Contents/Developer
See this article for more 1. Learn Swift by running Scripts

Related

gendef returning invalid syntax error

I am trying to install Theano for machine learning on my Windows 7 computer.
One of the last steps in installing the dependencies is to 'create a link library for GCC' by 'Opening up the Python shell and cd to C:\SciSoft. Then execute:
gendef WinPython-64bit-2.7.9.4\python-2.7.9.amd64\python27.dll
dlltool --dllname python27.dll --def python27.def --output-lib WinPython-
64bit-2.7.9.4\python-2.7.9.amd64\libs\libpython27.a
I've tried doing this but I get a invalid syntax error highlighted on 'WinPython'. I tried changing directory to go deeper and running gendef again and it also returned the same error. This is a copy and paste job from http://deeplearning.net/software/theano/install_windows.html#install-windows
I also followed the tutorial at the link to install Theano.
The line "Finally we need to create a link library for GCC. Open up the Python shell and cd to c:\SciSoft" is probably an error; "the Python shell" should be modified to "cmd.exe".
The two-line scripts are not python scripts, and can be successfully run on cmd.exe after changing directory to c:\SciSoft.

Clojure fireplace in vim asking for python

Trying to get get fireplace set up in vim but having trouble with some error messages.
When I type cpr in a clojure buffer the following error shows up:
Error detected while processing function <SNR>53_RunTests..fireplace#capture_te
st_run..<SNR>53_eval..fireplace#client..fireplace#platform..fireplace#register_
port_file..fireplace#nrepl_connection#open..fireplace#nrepl#for..<SNR>75_nrepl_
process..<SNR>75_nrepl_message..<SNR>75_nrepl_call..<SNR>74_nrepl_transport_cal
l..<SNR>74_nrepl_transport_dispatch:
line 6:
E605: Exception not caught: nREPL: zsh:1: command not found: python^#
Error detected while processing function <SNR>53_RunTests..fireplace#capture_te
st_run..<SNR>53_eval..fireplace#client..fireplace#platform:
line 9:
E171: Missing :endif
The thing I understand is that it cant find python. In my shell I can start python with the python command which will fire up 3.4.2.
Im using nixos
:echo has('python') returns 0
echo $PATH and :! echo $PATH return the same path.
What can I try in order to find what is actually causing this error?
You have to install/compile vim with python support for vim-fireplace to work, and this may not be the default on your system. I believe typing :help python will do this for you. If you don't get anything, you may have to recompile vim with python support, for which I'll direct you towards Google for now.
Another option if you have pip installed is to consider switching to neovim. Installing neovim with pip install neovim will get you python support. I've been using neovim lately, and it's worked pretty well for me.

Sublime Text 2 - BeautifyRuby don't work

i've installed BeautifyRuby in my Sublime Text 2 (running OS X Yosemite 10.10), but is not working, I receive this message when I try to cmd + ctrl + k:
Error: invalid output. Check your ruby interpreter settings
I've changed, as suggested https://github.com/CraigWilliams/BeautifyRuby , the sublime-settings file with:
"ruby": "/Users/alessiogastaldo/.rbenv/bin/ruby"
and also using the specific version:
"ruby": "/Users/alessiogastaldo/.rbenv/versions/1.8.7-p371/bin/ruby"
but with no success.
I've read the different solutions proposed (like https://github.com/CraigWilliams/BeautifyRuby/issues/52) but nothing works.
Anyone do know how to solve this?
I had the same problem too.
I solved with this:
In terminal, run the command: which ruby.
Copy the result. In my case was: "/home/user/.rbenv/shims/ruby"
Open your package settings. In my case: Preferences > Package Settings > BeautyfyRuby > Settings Default.
Add this line in the file: "ruby": "/home/user/.rbenv/shims/ruby",
You will need to install the htmlbeautifier gem.
Run the commmand in terminal: gem install htmlbeautifier
It works for me.

How can I use swift in Terminal?

I read What's new in Xcode 6. The article introduces some new feature about Xcode 6, and it says:
Command Line
Xcode’s debugger includes an interactive version of the Swift language, known as the REPL (Read-Eval-Print-Loop). Use Swift syntax to evaluate and interact with your running app or write new code in a script-like environment. The REPL is available from within LLDB in Xcode’s console, or from Terminal.
I want to know how to get the REPL?
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
then you can do one of these:
xcrun swift
lldb --repl
As of Xcode 6.1 - typing swift in the terminal launches the REPL as well.
Alternatively, if you don't want to mess up your current dev environment, you can just run:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
Step 1: Open Terminal
Step 2: Type "swift"
Step 3: There's no step 3
Example:
GoldCoast:~ macmark$ swift
Welcome to Swift! Type :help for assistance.
1> println("Hello, world")
Hello, world
2> var myVariable = 42
myVariable: Int = 42
3> myVariable = 50
4> let myConstant = 42
myConstant: Int = 42
5> println(myVariable)
50
6> let label = "The width is "
label: String = "The width is "
7> let width = 94
width: Int = 94
8> let widthLabel = label + String(width)
widthLabel: String = "The width is 94"
9> :exit
GoldCoast:~ macmark$
In Xcode 6.1.1 with Command Line Tools installed you can execute scripts by referencing directly to /usr/bin/swift the following way:
#!/usr/bin/swift
let variable: String = "string"
print("Test \(variable)")
In the same fashion as running Swift from the Terminal, you can also execute scripts.
Just use the following shebang, and run your script. (As per Chris Lattner, creator of Swift)
#!/usr/bin/env xcrun swift -i
If any one cares a simple Swift script shebang:
#!/usr/bin/env xcrun --sdk macosx swift
If specific target version is required
#!/usr/bin/env xcrun --sdk macosx swift -target x86_64-macosx10.11
If specific toolchain is required (like you want to use Swift 2.3 but you are using Xcode 8)
#!/usr/bin/env xcrun --toolchain com.apple.dt.toolchain.Swift_2_3 --sdk macosx swift -target x86_64-macosx10.11
If you want to use Swift 2.2 in your Xcode 7.3.1, let's assume Xcode 7.3.1 is located at /Applications/Xcode7.app
sudo xcode-select -s /Applications/Xcode7.app/
xcrun --sdk macosx swift
from now on the default active developer directory changed, you can check that using:
xcode-select -p
If you want to use snapshots provided by Swift.org, you should not miss Installation here.
as first answered by me in Run swift script from Xcode iOS project as build phase
** update as of xcode6 beta 4 **
this can also be done on xcode preferences. simply go to xcode -> preferences -> locations.
for command line tools simply select the version you want from drop down list options, refer picture below. (swift requires path to be xcode6's path).
I will leave my previous answer below as well.
what Kaan said and you can also use an apple script to make simple application so you can use it to switch back and forth.
open apple script > paste this below code & export it as an application so with just one click you can switch to default path or beta path (to use swift)
set xcode6Path to "xcode-select -switch /Applications/Xcode6-Beta.app/Contents/Developer"
set xcodeDefaultPath to "xcode-select -switch /Applications/Xcode.app/Contents/Developer"
display dialog "set xcode sdk path to " buttons {"xcode 6", "default"} default button 1
copy result as list to {buttonPressed}
if buttonPressed is "default" then
try
do shell script xcodeDefaultPath with administrator privileges
end try
else
try
do shell script xcode6Path with administrator privileges
end try
end if
then run > xcrun swift
disclaimer
the script assumes you have both xcode6-beta & xcode5 installed.
if you're a new developer who's trying out only xcode6beta you will not need any script or setting path manually. simply run xcrun swift as the path is already set for you.
when xcode6 is finally released you will need to reset your path back to default from this simple app and never use it again.
After installing the official Xcode 6.1 release, there is a swift command in /usr/bin/swift.
Bear in mind that if you have a Python different from the Apple-supplied Python in the path, swift can fail with ImportError: No module named site. In that case, make sure that you do export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin before calling swift.
The xcrun command will use the DEVELOPER_DIR environment variable to override the currently selected Xcode installation (as set with xcode-select). You can use that to construct a single command that'll run swift on the command line and put you in the REPL. That looks like this:
/usr/bin/env DEVELOPER_DIR=/Applications/Xcode6-Beta.app/Contents/Developer xcrun swift
and you can alias that to just 'swift':
alias swift="/usr/bin/env DEVELOPER_DIR=/Applications/Xcode6-Beta.app/Contents/Developer xcrun swift"
As an interesting side note, you can use the same kind of invocation to run a swift script just like you'd use bash or python by adding a -i:
#!/usr/bin/env DEVELOPER_DIR=/Applications/Xcode6-Beta.app/Contents/Developer xcrun swift -i
println("Hello World!")
Of course, once Xcode 6 is released officially and you switch to that as your default developer tools, you can drop the DEVELOPER_DIR=.. bits and just use "xcrun swift".
make sure you install xcode 6.0 ,but not 6.1
If you get an error:
<unknown>:0: error: the SDK 'MacOSX10.9.sdk' does not support Swift
just run
xcrun --sdk iphonesimulator8.0 swift
or you can
export SDKROOT="iphonesimulator8.0"
and then
xcrun swift
Use "xcodebuild -showsdks" to list the available SDK names.
if you install xcode 6.1,just
sudo xcode-select -s /Applications/*your-Xcode-6.1-path.app*/Contents/Developer
xcrun swift
For XCode6, run these commands:
$ sudo xcode-select -s /Applications/Xcode.app/Contents/Developer/
$ xcrun swift
If you get an error:
<unknown>:0: error: the SDK 'MacOSX10.9.sdk' does not support Swift
try:
xcrun swift -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk
open Terminal,
$sudo xcode-select -switch /Applications/Xcode6-Beta6.app/Contents/Developer
Notice: The Xcode6-Beta6.app should be replaced to appropriate version you installed
Then put this line alias swift='xcrun swift' to ~/.bash_profile
And,
$source ~/.bash_profile
$swift
There you go!
With the help of Swift REPL(Read Eval Print Loop).
Developers familiar with interpreted languages will feel comfortable in this command-line environment, and even experienced developers will find a few unique features
Launch Terminal.app and type swift and press enter. You’ll then be in the Swift REPL.
1> print("Hello Swift REPL")
Hello Swift REPL
2> 10 + 20
$R0: Int = 30
3> var name = "Yogendra Singh"
name: String = "Yogendra Singh"
4> print(name)
Yogendra Singh
5>

PLR Installation on Mac Lion

I am trying to install PL/R 8.3.0.13.1 on my MacBook Pro running OS X 10.7.5, Postgres 9.2 and R 2.15.2. I have found on the web a nice step-by-step guide for Windows but I can't find anything similar for Mac.
I got stuck when I run this command [as official documentation] ( http://www.joeconway.com/plr/doc/plr-install.html ):
USE_PGXS=1 make
Output:
make: pkg-config: Command not found
make: pkg-config: Command not found
make: pkg-config: Command not found
make: pkg-config: Command not found
make: pkg-config: Command not found
*** Cannot build PL/R because R_HOME cannot be found.
*** Refer to the documentation for details.
Clearly that means I need to create somehow R_HOME, variable and/or location...
Any idea how to do it?
The error message is actually a bit confusing. If you look at the Makefile of PL/R, the logic is that it uses R_HOME to find R when set, otherwise it tries pkg-config. You have neither set, so it bails out.
I recommend going the pkg-config route if possible. The R_HOME route appears to assume an R installation scheme that might not be universally applicable. Perhaps it applies to builds straight from source.
The above applies to all platforms. Now on OS X, it depends on how you installed R. For example, if you used MacPorts, it would go something like this:
sudo port install pkgconfig
sudo port install R
and then build PL/R itself:
make USE_PGXS=1
But that will break because PL/R does not expect that MacPorts separates the R headers into two separate directories (architecture-dependent and -independent I suppose).
Homebrew might work better, but the principle is the same.
You need to figure out what you should set your PLR environment R_HOME variable. In a terminal session I get this
computername:~ username$ R RHOME #only enter stuff after"$"
/Library/Frameworks/R.framework/Resources
This is at the bottom of that page you linked to:
"Tip: R_HOME must be defined in the environment of the user under which PostgreSQL is started, before the postmaster is started. Otherwise PL/R will refuse to load. See plr_environ(), which allows examination of the environment available to the PostgreSQL postmaster process. "
This is from a webpage describing the problem and offering a fix:
To fix: Add a "R_HOME = '/usr/lib/R' " to /etc/postgresql/version/cluster/environmen
Example Fix for version 8.1:
$ sudo -s
# echo -e "\nR_HOME = '/usr/lib/R'" >> /etc/postgresql/8.1/main/environment
# exit
To Test:
$ sudo /etc/init.d/postgresql-8.1 restart
$ sudo -u postgres psql plr_test
plr_test=# select test();
test
------

Resources