Not by chance it is said that the whole law is to love God and your neighbor. Love of a neighbor is a special case. The neighbor can be or not to be. God is always there. And because of that a man alone in the wilderness, in a prison can obey the law, loving God and all His manifestations available to him at least in the memories, in the views and thoughts.