I am setting a project path to some env variable like PROJECT_HOME by us using os.environ like this:
os.environ['PROJECT_HOME'] = os.getcwd()
so I can use %cd $PROJECT_HOME/abc/xyz in later cell
However, the system return this:
[Errno 2] No such file or directory: '${PROJECT_HOME}/abc/xyz'
Is there a way to use env variable in %cd?
This works for me: %cd {os.environ['PROJECT_HOME']}
I just realized the magic %cd could access python variable. Therefore it could be done like this:
import os
PROJECT_HOME = os.getcwd()
%cd {PROJECT_HOME}
Having said that, the answer by Daniel is the right answer to the question because I asked how to %cd a path containing an environment variable.
Related
Right now I'm trying to create wallet for TON.
I downloaded and built Fift interpreter an was trying to create new wallet with: ./crypto/fift new-walelt.fif
[ 1][t 0][1559491459.312618017][fift-main.cpp:147] Error interpreting standard preamble file `Fift.fif`: cannot locate file `Fift.fif`
Check that correct include path is set by -I or by FIFTPATH environment variable, or disable standard preamble by -n.
Although my path variable is set. Could anyone please help me with this?
First, locate {{lite-client-source-direcotry}}/crypto/fift
This is not the build directory, that's the directory where are the source files (lite-client that you downloaded). So verify you have that it contains Fift.fif file.
If you installed it in the user working directory, it should be:
~/lite-client/crypto/fift/
Now, you should either set FIFTPATH variable to point to this directory or run fift with -I option:
export FIFTPATH=~/lite-client/crypto/fift/
./crypto/fift new-walelt.fif
Or
./crypto/fift -I~/lite-client/crypto/fift/ new-walelt.fif
Have you tried ./crypto/fift -I<source-directory>/crypto/fift new-wallet.fif instead of setting environment variable? Are Fift.fif and Asm.fif library files inside FIFTPATH?
Make sure you have followed all the instruction written here:
https://test.ton.org/HOWTO.txt
It should work if you do all the above instruction correctly. If not, it might be a bug. Remember that TON is in a very early beta strage. You can submit the issue here:
https://github.com/copperbits/TON/issues
You also can use this:
cd ~/liteclient-build
crypto/fift -I/root/lite-client/crypto/fift/lib -s /root/lite-client/crypto/smartcont/new-wallet.fif -1 wallet_name
Try this (worked for me)
export FIFTPATH=~/lite-client/crypto/fift/lib
./crypto/fift new-wallet.fif
It looks like my Jupyter notebook picks up everything that I export in my .bash_profile, but nothing that I alias.
I think ! uses bin/sh, so it's understandable that the aliases from the bash profile don't port over, but the %%bash magic also does not pick up the aliases I've written.
Is there a way to make the aliases in my bash profile available through ! (ideally) or, at the least, using %%bash?
This seems to work (python3, modified from a hack I found in a jupyter issue)
import subprocess
lines = subprocess.check_output('source ~/.bash_profile; alias',shell=True).split(b'\n')
manager = get_ipython().alias_manager
for line in lines:
line = line.decode("utf-8")
split_index = line.find('=')
cmd = line[split_index+1:]
alias = line[:split_index]
cmd = cmd[1:-1]
print ("ALIAS:{}\t\tCMD:{}".format(alias,cmd))
manager.soft_define_alias(alias, cmd)
Here's another alternative, which is less a solution than a workaround: you can define aliases locally to the notebook using the %alias magic, and make those aliases available in the future using the %store magic. More alias trickiness here: https://github.com/ipython/ipython/wiki/Cookbook:-Storing-aliases
More on the %store magic here: http://ipython.readthedocs.io/en/stable/config/extensions/storemagic.html
The next step is hacking the %store magic to persist these aliases: https://github.com/ipython/ipython/blob/master/IPython/extensions/storemagic.py
For posterity, here are the results of some experiments I ran before finally finding a solution:
I sourced my .bash_profile in a %%bash cell. From within that cell, I was able to interrogate the values of variables I defined in my .bash_profile, and was able to list aliased commands by invoking alias. However, I was still not able to use aliased commands. Additionally, variables defined in my .bash_profile were only accessible inside the cell with the source call: trying to access them in subsequent %%bash cell didn't work, and the alias command also failed. More interesting still: if I sourced using !, I wasn't able to interrogate variables defined in my bash profile nor list my aliases with ! shell commands in the same cell.
Suffice it say, the %%bash magic is finicky.
I have the following env file which is run whenever the shell starts:
PATH=/Users/paulcowan/bin:$PATH
PATH=$PATH:~/bin
PATH=$PATH:$HOME/.local/bin:$PATH
PATH=$PATH:/usr/local/bin:/usr/bin:/bin
PATH=$PATH:"$RBENV_ROOT/bin:$PATH"
export PATH
But when I run echo $PATH
I get:
/Users/paulcowan/.nvm/versions/node/v5.0.0/bin:/usr/local/rbenv/shims:PATH:/Users/paulcowan/.local/bin:/Users/paulcowan/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/MacGPG2/bin:/usr/local/rbenv/shims:PATH:/Users/paulcowan/.local/bin:/Users/paulcowan/bin:/Users/paulcowan/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/rbenv/bin:PATH:/Users/paulcowan/.local/bin:/Users/paulcowan/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/MacGPG2/bin:/usr/local/rbenv/shims:PATH:/Users/paulcowan/.local/bin:/Users/paulcowan/bin:/Users/paulcowan/bin:/usr/local/bin:/usr/bin:/bin
With the same values repeating.
How can I properly configure my path?
You repeated the $PATH at the beginning and end of several of the lines:
PATH=$PATH:$HOME/.local/bin:$PATH
PATH=$PATH:"$RBENV_ROOT/bin:$PATH"
Why not just set it like this?
export PATH=/Users/paulcowan/bin:~/bin:$HOME/.local/bin:/usr/local/bin:/usr/bin:/bin:$RBENV_ROOT/bin:$PATH
If I well understood what your script tries to do, the correct code could be:
PATH=/Users/paulcowan/bin:$PATH
PATH=~/bin:$PATH
PATH=$HOME/.local/bin:$PATH
PATH=$PATH:/usr/local/bin
PATH=/usr/bin:$PATH
PATH=/bin:$PATH
PATH=$PATH:$RBENV_ROOT/bin
export PATH
I am trying to run the following command from Julia:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/user/.julia/v0.3/Smile/deps/downloads
When I run it as-is it tries to replace $LD_LIBRARY_PATH with a local variable.
When I escape the $, it puts quotes around the command, which invalidates it.
julia> cmd = `export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/tim/.julia/v0.3/Smile/deps/downloads`
ERROR: LD_LIBRARY_PATH not defined
julia> cmd = `export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/home/tim/.julia/v0.3/Smile/deps/downloads`
`export 'LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/tim/.julia/v0.3/Smile/deps/downloads'`
I would like to run the command in a form similar to:
run(`export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$newpath`)
How do I properly handle the dollar sign?
Thank you
*note: pasting the command directly into terminal and running it does work
In Julia, backticks are not completely equivalent to running the corresponding command at the shell. You can't interpolate environmental variables with $ (although $(get(ENV, "varname", "") should match the shell's behavior), and export is a shell built-in, not a command, so I don't think you can run it. Also, even if backticks shelled out, export would only change the environment of the subshell, not the calling process.
You should be able to set LD_LIBRARY_PATH from Julia as:
ENV["LD_LIBRARY_PATH"] = "$(get(ENV, "LD_LIBRARY_PATH", "")):$newpath"
but you should avoid this if possible. If your intent is to ccall a specific library, you can pass the library path directly to ccall, perhaps using find_library as you indicated in a comment if you don't know the full path advance. If you need to set LD_LIBRARY_PATH because the library needs to load other libraries, I'm not sure if there's a better way, but note that LD_LIBRARY_PATH is platform-specific. You might be able to dlopen the dependent libraries first, but I haven't tested that.
My PATH environment variable right now is:
./subTmp:/usr/local/bin
How do I remove the ./subTmp part from it?
Thanks.
The details vary a bit by installation and by local custom, but generally you have a file named either .profile, .login, or .bashrc in your home directory that contains a line something like
PATH = ./subTmp:/usr/local/bin
Just edit it to be whatever you need.
this should do
export PATH=/usr/local/bin