Virtualenv: No module named virtualenvwrapper, path is wrong - macos

Why after installing virtualenv and virtualenvwrapper and adding
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /Users/<user>/Library/Enthought/Canopy_64bit/User/bin/virtualenvwrapper.sh
to my .bash_profile and running $ source ~/.bash_profile, I encounter:
/Library/Frameworks/Python.framework/Versions/7.3/Resources/Python.app/Contents/MacOS/Python: No module named virtualenvwrapper
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenv has been installed for
VIRTUALENVWRAPPER_PYTHON=/Library/Frameworks/Python.framework/Versions/Current/bin/python and that PATH is set properly.
?
My .bash_profile looks like:
# 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
##
# Your previous /Users/<user>/.bash_profile file was backed up as /Users/<user>/.bash_profile.macports-saved_2012-11-06_at_11:39:22
##
# MacPorts Installer addition on 2012-11-06_at_11:39:22: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.
# virtualenvwrapper
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /Users/<user>/Library/Enthought/Canopy_64bit/User/bin/virtualenvwrapper.sh
# Added by Canopy installer on 2014-01-26
# VIRTUAL_ENV_DISABLE_PROMPT can be set to '' to make bashprompt show that Canopy is active, otherwise 1
VIRTUAL_ENV_DISABLE_PROMPT=1 source /Users/<user>/Library/Enthought/Canopy_64bit/User/bin/activate

So figured it out. It turns out that when I installed EPD for python a while back, it added the first few lines:
# 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
in my .bash_profile. Having updated my python to Enthought Canopy, I needed to change these lines to this:
# set path for current python
PATH="/Users/<user>/Library/Enthought/Canopy_64bit/User/bin:${PATH}"
export PATH
and everything works now. However as it turns out that won't work at the end of the day because with Enthought, it backports venv, which is a python 3 standard as talked about here.

Related

Unable to add folders to PYTHONPATH when creating conda environment

I have a script that is making a conda virtual environment where functions need to be imported from folders outside of the repo. I have tried two approaches to add the folders to the path:
Conda develop:
os.system(conda run -n test_env conda develop ' + PACKAGE_PATH)
Results in:
Permission denied [PACKAGE_PATH]
Create conda.pth manually
path = os.path.join(env_path, 'lib')
if not os.path.exists(path):
os.mkdir(path)
path = os.path.join(path, 'site-packages')
if not os.path.exists(path):
os.mkdir(path)
env_path_file = os.path.join(path, 'conda.pth')
with open(env_path_file, 'w+') as f:
write_line(f, PACKAGE_PATH)
The file is created successfully. But, setting the conda interpreter from test_env (in Pycharm) and doing import sys; sys.path does not show [PACKAGE_PATH] and functions cannot be imported from its folders.
Any suggestions?
Thank you.
This is resolved by using conda develop from outside the environment:
conda develop [package_path]
not
conda run -n conda develop [package_path]

Anaconda lists some environments twice

(base) PS C:\Users\<username>\Desktop> conda info --envs
# conda environments:
#
base * C:\Users\<username>\Anaconda3
proj_1 C:\Users\<username>\Anaconda3\envs\proj_1
proj_2 C:\Users\<username>\Anaconda3\envs\proj_2
C:\Users\<username>\anaconda3
proj_2 C:\Users\<username>\anaconda3\envs\proj_2
This is on Windows 10. There's also an old environment present in the C:\Users\<username>\anaconda3\envs directory that I deleted using conda remove -n proj_0 --all in the past. C:\Users\<username>\.conda\environments.txt file contents:
C:\Users\<username>\anaconda3
C:\Users\<username>\anaconda3\envs\proj_1
C:\Users\<username>\Anaconda3
C:\Users\<username>\Anaconda3\envs\proj_2
What's up with all the casing and repeat environments? I don't remember changing anything manually. I've just tried removing the old environment dir (proj_0) manually, but got an error saying the folder is open in another program (I'm guessing conda).
Edit: conda config --show envs_dirs output:
envs_dirs:
- C:\Users\<username>\Anaconda3\envs
- C:\Users\<username>\.conda\envs
- C:\Users\<username>\AppData\Local\conda\conda\envs

Conda does not set up properly path for JDK for pyjnius

I have installed pyjnius with conda. However, when I try to import pyjnius it fails
> from jnius import autoclass
File
"C:\Users\OEM\Miniconda3\envs\example-env\lib\site-packages\jnius\__init__.py",
line 12, in <module>
from .jnius import * # noqa ImportError: DLL load failed: The specified module could not be found.
Together with pyjnius conda installs also openjdk. Next, pyjnius looks for jvm.dll in one of PATH directories. DLL could be found in
C:\Users\OEM\Miniconda3\pkgs\openjdk-11.0.1-1017\Library\bin\server
but conda does not include it in PATH. It adds another folder in PATH:
C:\Users\OEM\Miniconda3\envs\example2-env\Library\jre\bin\server
while this directory is missing: JRE has not been installed, only JDK. I can, obviously, include first directory in my PATH, however, this would bypass conda virtual environments concept. How can I solve this problem in an elegant way?
Here's environment.yml to reproduce the problem:
name: example-env
channels:
- conda-forge
dependencies:
- python=3.7
- Cython
- pyjnius
Next, I create and activate as follows:
conda env update --file environment.yml
conda activate example-env

PyCharm: Can't find spark-submit

I am trying to run a test file in PyCharm with unittest.
It errors with this message:
FileNotFoundError: [Errno 2] No such file or directory: 'myfolder/opt/spark/./bin/spark-submit': 'myfolder/opt/spark/./bin/spark-submit'
I think it has something to do with my .bash_profile which a coworker helped configure. It looks like this:
export SPARK_HOME=myfolder/opt/spark
export PATH=$SPARK_HOME/bin:$PATH
export PATH=$HOME/.node_modules_global/bin:$PATH
# added by Anaconda3 5.1.0 installer
export PATH="/Users/myname/anaconda3/bin:$PATH"
Important to note, the path myfolder/opt/spark/./bin/spark-submit does not exist, but myfolder/opt/spark/bin/spark-submit does. I have no idea why the extra ./ is being added to the path.

Dynamic Shared Library error when creating exe from cx_freeze

I have a python file using OpenCV library.I want this in as an executable file.
Came across this cx_freeze
Example:
ABC.py(file using opencv library)
Content of setup.py is given below
from cx_Freeze import setup, Executable
setup( name = "ABC",
version = "0.1",
description = "Testing",
executables = [Executable("ABC.py")],
)
I ran this command in the terminal
python setup.py install
It is stopping after showing this error message
copying /Users/name/.virtualenvs/test/lib/python3.6/site-packages/cv2.so -> build/exe.macosx-10.12-x86_64-3.6/lib/cv2.so
copying /Users/name/.virtualenvs/test/bin/../lib/libopencv_reg.3.3.dylib -> build/exe.macosx-10.12-x86_64-3.6/libopencv_reg.3.3.dylib
error: [Errno 2] No such file or directory: '/Users/name/.virtualenvs/test/bin/../lib/libopencv_reg.3.3.dylib'
I know from the error message that libopencv_reg.3.3.dylib is not found.
I'm running this on a python virtual environment.
This is my bash_profile content
#Homebrew
export PATH=/usr/local/bin:$PATH
#export WORKON_HOME=$HOME/.virtualenvs
# Virtualenv/VirtualenvWrapper
source /usr/local/bin/virtualenvwrapper.sh
#export PROJECT_HOME=$HOME/Devel
#export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python
#export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
#export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages'
I'm confused please help me out fix this.
Guidance would really be helpful, if this question can be posted else where let me know rather than down voting it.
can you search your filesystem for the missing file? When you find it you can set PERL5LIB or use -I switch to set the location into the perl path
perl library path
Shared the same on OpenCV forum
here's the response I got there
Looks like we have build OpenCV in such a way that other shared objects(.so) files are not dependent.

Resources