conda activate on powershell - powershell

Fresh install of conda. I'm trying to activate an environment (any environment) and I get the following
(base) PS C:\Users\AndrewBergan> conda activate test123
# >>>>>>>>>>>>>>>>>>>>>> ERROR REPORT <<<<<<<<<<<<<<<<<<<<<<
Traceback (most recent call last):
File "C:\Users\AndrewBergan\AppData\Local\Continuum\anaconda3\lib\site-packages\conda\cli\main.py", line 138, in main
return activator_main()
File "C:\Users\AndrewBergan\AppData\Local\Continuum\anaconda3\lib\site-packages\conda\activate.py", line 940, in main
print(activator.execute(), end='')
File "C:\Users\AndrewBergan\AppData\Local\Continuum\anaconda3\lib\site-packages\conda\activate.py", line 173, in execute
return getattr(self, self.command)()
File "C:\Users\AndrewBergan\AppData\Local\Continuum\anaconda3\lib\site-packages\conda\activate.py", line 150, in activate
builder_result = self.build_activate(self.env_name_or_prefix)
File "C:\Users\AndrewBergan\AppData\Local\Continuum\anaconda3\lib\site-packages\conda\activate.py", line 275, in build_activate
return self._build_activate_stack(env_name_or_prefix, False)
File "C:\Users\AndrewBergan\AppData\Local\Continuum\anaconda3\lib\site-packages\conda\activate.py", line 332, in _build_activate_stack
self._replace_prefix_in_path(old_conda_prefix, prefix))
File "C:\Users\AndrewBergan\AppData\Local\Continuum\anaconda3\lib\site-packages\conda\activate.py", line 550, in _replace_prefix_in_path
assert last_idx is not None
AssertionError
What am I doing wrong?

Turns out for some reason Continuum/anaconda3/Library/bin did not get added to my path. Adding this fixed the problem.
Edit:
As noted in the comment below, other modifications to your path might be needed. I was able to determine what was missing from my path by adding a couple print statements to activate.py and comparing the output from the conda bash window and powershell.

you can just update conda using following code
conda update -n base conda
Because conda 4.6.14 fixed this problem.

conda start to support Powershell in version 4.6. upgrade your conda, then run this:
conda init
you should be fine then.

I was too struggling with this trouble for a long time but couldn't find any solution online.
But I found it at last.
This is occurring because Windows PowerShell is not allowed to run local PowerShell scripts. It can be enabled in developer settings.
On windows 10
Settings > Update & Security > For developers > Enable PowerShell to run local PowerShell scripts without signing in.
see where to enable

Related

cd: /D: No such file or directory error message under windows 10

I wrote a perl script that runs command strings using the system perl command. And under Windows 10, when it comes to running a command like
cd /D R:/some_path…`
it gives the following error message
sh: line 0: cd: /D: No such file or directory
but directly running the same command via Windows 10 cmd is successful. What's odd to me here is that this error message is used to appear on Linux systems. what could be causing this behaviour, and how can I get it to work correctly?
thanks for all the comments. I figured out that the Perl I'm using is inside the cygwin/bin folder. I changed it to regular perl under windows and it works great.

jupyter kernelspec no such file or directory /lib/libstdc++.so.6.0.21

I'm trying to flesh out the workflow for a JupyterHub server in the case where a user creates an environment and wants to share it with another user. I want to test out one of the two methods.
I am trying to create an environment in a public path, and then have another user add the conda environment as a kernel. So far it looks like this.
# How the environment is created
jupyter#ip:~$ conda create -p /home/envs/test --clone root
# Current setup
nick {~}$ jupyter kernelspec list
Available kernels:
python3 /opt/conda/share/jupyter/kernels/python3
nick {~}$ conda env list
# conda environments:
#
test /home/envs/test
nenv /home/nick/.conda/envs/nenv
base * /opt/conda
nick {~}$ cat .condarc
envs_dirs:
- /home/envs
My problem is I get an error when I try and install the kernel libstdc++.so.6.0.21 does not exist. What is libstdc++.so.6.0.21?
# error when trying to install kernel
nick {~}$ jupyter kernelspec install --user /home/envs/test
[InstallKernelSpec] Removing existing kernelspec in /home/nick/.local/share/jupyter/kernels/test
Traceback (most recent call last):
File "/opt/conda/bin/jupyter-kernelspec", line 11, in <module>
sys.exit(KernelSpecApp.launch_instance())
File "/opt/conda/lib/python3.7/site-packages/traitlets/config/application.py", line 658, in launch_instance
app.start()
File "/opt/conda/lib/python3.7/site-packages/jupyter_client/kernelspecapp.py", line 273, in start
return self.subapp.start()
File "/opt/conda/lib/python3.7/site-packages/jupyter_client/kernelspecapp.py", line 143, in start
replace=self.replace,
File "/opt/conda/lib/python3.7/site-packages/jupyter_client/kernelspec.py", line 346, in install_kernel_spec
shutil.copytree(source_dir, destination)
File "/opt/conda/lib/python3.7/shutil.py", line 365, in copytree
raise Error(errors)
shutil.Error: [('/home/envs/test/lib/libstdc++.so.6.0.21', '/home/nick/.local/share/jupyter/kernels/test/lib/libstdc++.so.6.0.21', "[Errno 2] No such file or directory: '/home/envs/test/lib/libstdc++.so.6.0.21'")]
Note: I found this question which is similar; however, I found through this github thread why gcc had to be removed, and I already verified that it didn't exist in my environment with:
nick {~}$ conda list --name test | grep 'gcc'
_libgcc_mutex 0.1 main
libgcc 7.2.0 h69d50b8_2
libgcc-ng 8.2.0 hdf63c60_1
I already have libgcc installed at a higher version as you can see above so I didn't think the other answer would do too much good either.
filename shows up as red with this, so I believe the link is broken.
(test) nick {~}$ ls -al /home/envs/test/lib/libstdc++.so.6.0.21
lrwxrwxrwx 1 jupyter jupyter 19 Aug 9 09:42 /home/envs/test/lib/libstdc++.so.6.0.21 -> libstdc++.so.6.0.24
I realized I was using jupyter kernelspec in a non-intended way here. It is not intended to actually create the kernel, but only to add a kernelspec if it exists (see here, at the bottom).
There are two options for writing a kernel:
You can reuse the IPython kernel machinery to handle the communications, and just describe how to execute your code. This is much simpler if the target language can be driven from Python. See Making simple Python wrapper kernels for details.
You can implement the kernel machinery in your target language. This is more work initially, but the people using your kernel might be more likely to contribute to it if it’s in the language they know.
So, in my case what I really wanted to do was use IPythons utilities (option 1 above) which is documented well here. In which case to add the shared conda environment as a kernel in a way the users can access it I just need to run.
su - <user>
conda activate test
python -m ipykernel install --user --name test --display-name "Python (test)"

How to allocate a pseudo-tty in which to run scripts from IDE?

Eclipse (and other IDEs, such as Pycharm/IntelliJ), don't seem to use a proper terminal with which to run programs. This can lead to some problems when a program needs to work with a proper stdin/stdout.
For example, the simple python script
# Exit upon any keypress
import sys
import termios
import tty
fd = sys.stdin.fileno()
tty.setraw(sys.stdin.fileno())
while not sys.stdin.read(1):
pass
Will function perfectly when run directly from bash, but will fail with the following error when from from any IDE
Traceback (most recent call last):
File "/Users/anishmoorthy/Code/termserver/turst.py", line 19, in <module>
while readchar() is None:
File "/Users/anishmoorthy/Code/termserver/turst.py", line 10, in readchar
tty.setraw(sys.stdin.fileno())
File "/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tty.py", line 20, in setraw
mode = tcgetattr(fd)
termios.error: (25, 'Inappropriate ioctl for device')
More generally, any calls to tcgetattr(<stdin>) will fail.
I was wondering if there were any plugins or settings, Eclipse or IntelliJ, which would fix these errors by running scripts in a proper bash process.
IntelliJ actually has an ."Emulate terminal in output console" checkbox in its run configuration options which fixes these errors, but for some reason it doesn't register my enter key- making it more or less useless
For IntelliJ IDEA and PyCharm there is a hidden option that can be enabled by adding
-Drun.processes.with.pty=true
in Help | Edit Custom VM Options.
See here for the related request.

Can't run ibm_db in Jupyter Notebook

I am trying to run ibm_db in a jupyter notebook. When I run ibm_db I get the below error.
ImportError Traceback (most recent call last)
in ()
----> 1 import ibm_db
ImportError: dlopen(/Users/myName/anaconda/envs/householding/lib/python3.6/site-packages/ibm_db.cpython-36m-darwin.so, 2): Library not loaded: libdb2.dylib
Referenced from: /Users/myName/anaconda/envs/householding/lib/python3.6/site-packages/ibm_db.cpython-36m-darwin.so
Reason: image not found
When i run os.getcwd() I get '/Users/myName'
What I think is happening is that because my current directory is to levels down from the start of the path dlopen is looking for, it is failing. I've done some looking around but can't find a way to change where dlopen is looking
You have to actually update your environment variable
DYLD_LIBRARY_PATH
to include
/ibm_db-2.0.8-py3.6-macosx-10.6-intel.egg/clidriver/lib
If you have installed ibm_db-2.0.8 on python3.6,
On terminal write
export DYLD_LIBRARY_PATH=/Users/myName/anaconda/envs/householding/lib/python3.6/site-packages/ibm_db-2.0.8-py3.6-macosx-10.6-intel.egg/clidriver/lib
It should work like a charm after this.
For reference checkout this:Issues with MAC OS X
I was having the same error and found that the installDSDriver script creates a file at /Applications/dsdriver/db2profile stating the below:
# NAME: db2profile
#
# FUNCTION: This script sets up a default database environment for
# Bourne shell or Korn shell users.
#
# This file is tuned for IBM Data Server Driver Package only.
#
# USAGE: . db2profile
# This script can either be invoked directly as above or
# it can be added to the user's .profile file so that the
# database environment is established during login.
#
so I just added on my ~/.bash_profile the line below:
source /Applications/dsdriver/db2profile
Open a new terminal window or restart and should work.
This file exports all the environment variables needed for the db2cli command to work.

Why is -bash: PATH: command not found displayed when I open my terminal window?

I installed EPD Free 7.3.2 and it was running fine until I wanted to modify PATH to point to where my Python scripts are. I gave up on that and reverted back to my original .bash_profile file.
# Setting PATH for EPD_free-7.3-2
# The orginal version is saved in .bash_profile.pysave
PATH = "/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"
export PATH
When launching terminal, I get this:
Last login: Thu Jan 3 08:50:20 on ttys000
-bash: PATH: command not found
However, I am able to run iPython and all the libs that come with EPD w/o problems. Anybody knows what the problem is with "PATH: command not found"?
The spaces around the = are a problem. Use this assignment:
PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"
You need to remove the spaces around =:
PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"
Otherwise you're trying to run the (non-existent) command PATH with = and "/Library..." as its arguments.