I am using Octave on Window vista. I am using 4 package in my code. But every time I restart octave, I have to load manually from command line, 'pkg load ...' Is there a way to load them permanently so that whenever Octave is started it finds them in its path.
4 Answers
When Octave starts, it runs ~/.octaverc
. If you want Octave to automatically load a package, simply add a pkg load pkg-name
command to it. If the files does not exist, create it.
If you do this, remember that other people may not have Octave configured to load packages at startup. Therefore, if you write code for others, remember that your programs still need to load the packages they require.
Do not use pkg install -auto ...
or pkg rebuild -auto ..
because that will stop working on the next Octave release.
-
For completion sake, the octaverc file in Windows executable would be at: C:\Octave\Octave-4.2.1\share\octave\site\m\startup\octaverc. Hope it helps for those looking for the file, as it took me a while to hunt down the octaverc file. Sep 25, 2017 at 9:54
-
1@LyeHengFoo not completely true. That's the system-wide
octaverc
file. Changes to that file will apply to all users in the system. This type of changes should be made on the useroctaverc
file so it doesn't affect anyone else (maybe not important if you are the only user). The file you are looking for is on your home directory (whatever~
expands to on windows). Sep 25, 2017 at 11:14 -
1You're absolutely right. That is the site setting octaverc, that will be applicable to all users. I have just figured out ~/.octaverc in linux is actually %USERPROFILE%/.octaverc. And after manually creating this file %USERPROFILE%/.octaverc, it works as expected, but only for me this time. Thanks for highlighting my mistake. Sep 26, 2017 at 13:03
-
2Using the command
edit '~/.octaverc'
seems to work cross-platform. Feb 5, 2018 at 14:13
I got the answer. It can be set at the time of package installation. install with following command pkg install -auto [package name] It will be load every time octave is started.
-
Or, once installed, you can run
pkg rebuild -auto image
, for example for theimage
package Jun 23, 2016 at 10:12 -
2In Octave 4.2.1, we will get this if we try to use -auto option:
warning: pkg: autoload is no longer supported. Add a 'pkg load ...' command to octaverc instead.
Sep 26, 2017 at 13:46
create a file named "startup.m" with this content:
packs = pkg('list');
for jj = 1:numel(packs),
pkg('load', packs{jj}.name);
end
in the directories "octave-home/share/octave/version/m/startup/octaverc" and "octave-home/share/octave/site/m/startup/octaverc". (https://www.gnu.org/software/octave/doc/v4.2.1/Startup-Files.html) So it loads all packages at startup.
Install the packages on your working directory. Then add "pkg load pkg_name" command to octave-1.1~\share\octave\site\m\startup\octaverc. It will load the package every time.