How to can get the path of virtualenv in pipenv?
can configure it to use a custom path for newly created virtualenv?
The following should give you the paths
$ pipenv --where
/home/wonder/workspace/myproj
$ pipenv --venv
/home/wonder/PyEnvs/myproj-BKbQCeJj
Adding to Sewagodimo Matlapeng's answer for the second part of the question:
can configure it to use a custom path for newly created virtualenv?
According to documentation, you can set the base location for the virtualenvs with the environment variable WORKON_HOME. If you want to place the virtualenv specifically in <project>/.venv, set the environment variable PIPENV_VENV_IN_PROJECT.
e.g., running:
export WORKON_HOME=/tmp
pipenv install
Would place the virtualenv in /tmp/<projectname>-<hash>.
I create a command to handle this:
https://github.com/tw-yshuang/Ubuntu-Setup-Scripts/blob/8917578f9ad95be03f48608b7068337215d33f92/config/.customfunction#L12
From line 12 ~ 105
Usage: pipenv_correspond [OPTION]
OPTION:
ls, --list list all the corresponding projects_root & venvs
uls, --useless list all the not existing projects_roots that still have corresponding venvs
npr, --no-project-root hide projects_root
rm, --remove remove all the venvs from command: "ls" or "uls", deafult is use "uls"
# example
$ pipenv_correspond ls
There have some options that suggest you enable this command:
Recommend, create a ~/.customfunction file and
paste it, then use this command:
$ echo '# customfunction\nsource ~/.customfunction' >> <shell_profile>
shell_profile, e.g. ~/.bash_profile, ~/.zshrc
you can copy this code from line 12 ~ 105 to your shell_profile.
You can simple use following command:
pipenv --where
Related
I have a python file in: '/home/username/scripts/pyscript' and I want set a word for execute directly this script.
I want do this "python3 /home/username/scripts/pyscript/main.py arg1 arg2" but looks like
this "myscript arg1 arg2"
Is this posible?
Thank you anyway.
It is possibile in a number of ways. Links are for Bash, supposedly your shell but the ideas always apply.
First option: make a shell alias
alias myscript='python3 /home/username/scripts/pyscript/main.py'
Be sure to add the alias to your .profile to make it survive logout.
Second option: define a wrapper script. Create a file with the following content, named after your desired command (e.g. myscript):
#!/bin/bash
python3 /home/username/scripts/pyscript/main.py "$#"
save it and make it executable, then call it :
chmod +x myscript
./myscript arg1 arg2
Be sure to copy the script in a folder in your PATH (check where with echo $PATH) to be able to call it from any folder.
You can also use pyinstaller to create a single file executable:
Step 1: Install pyinstaller
[Note: best practice is to do this in a virutalenv]
$ pip install pyinstaller
Step 2: Run pyinstaller against your script
$ pyinstaller --console --onefile /home/username/scripts/pyscript
$ pyinstaller pyscript.spec # use this after the first run
Step 3: Test the generated executable
$ cd /home/username/scripts/dist # generated by pyinstaller
$ pyscript arg1 arg2
Step 4: Leverage the $PATH variable
$ cp /home/username/scripts/dist/pyscript /usr/bin
You should now be able to run the executable from anywhere.
It should be noted that the executable that is generated is OS specific. For example, if you generate it on an Ubuntu machine, it will only run on Ubuntu (Debian based). The same holds true for Windows and other Linux distros.
Finally I solver with the help of #pierpaciugo
I add a alias at the end of the .bashrc for make it persistent:
alias create='bash /home/username/Programming/Python/GithubAPI/script.sh'
I couldn't use only alias because I have my python dependencies on a virtual environment so if I try this i could not add params to my python script.
For that I create this bash script:
#!/bin/bash
source /home/username/Programming/Python/GithubAPI/venv/bin/activate && python3 /home/username/Programming/Python/GithubAPI/main.py $# && deactivate
Now I can write "create param1 param2" and it works.
I am using all global paths but could be a good idea add the script in a folder in my PATH.
I'm using vcf2maf to annotate variants as part of a snakemake pipeline
rule vcf2maf:
input:
vcf="vcfs/{sample}.vcf",
fasta=vep_fasta,
vep_dir=vep_dir
output:
"mafs/{sample}.maf"
conda:
"../envs/annotation.yml"
shell:
"""
vcf2maf.pl --input-vcf {input.vcf} --output-maf {output} \
--tumor-id {wildcards.sample}.tumor \
--normal-id {wildcards.sample}.normal \
--ref-fasta {input.fasta} --filter-vcf 0 \
--vep-data {input.vep_dir} --vep-path [need path]
"""
The conda environment has two packages: vcf2maf and vep. vcf2maf requires a path to vep to run properly, but I'm not sure how to access vep's path since it's stored inside the conda environment which will have a user specific absolute path. Is there an easy way to get vep's path so I can refer to it for --vep-path?
You could use the unix which command like:
veppath=`which vep`
vcf2maf.pl --vep-path $veppath ...
[vep path is] stored inside the conda environment which will have a user specific absolute path
The variable CONDA_PREFIX contains the path to the current conda environment. so you could also do something like:
vcf2maf.pl --vep-path $CONDA_PREFIX/bin/vep ...
Currently using tox to test a python package, and using a python library (chromedriver-binary) to install chromedriver.
This library creates a script (chromedriver-path) which when called outputs the PATH where chromedriver is installed. The usual way to use this is to run:
export PATH=$PATH:`chromedriver-path`
I've tried the following without success in tox.ini
setenv=
PATH = {env:PATH}{:}`chromedriver-path`
This errors as expected:
FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver': 'chromedriver'
Implying that the setenv command is never called/run.
commands=
export PATH=$PATH:`chromedriver-path
This fails with:
ERROR: InvocationError for command could not find executable export
How do I make this work?
Commands can't change their parent processes' environment variables, and thus can't change the environment variables of subsequent commands launched by forking that parent; they can only set environment variables for themselves or their own children.
If you were able to collect the output of chromedriver-path before starting tox, this would be moot. If it's only available in an environment tox itself creates, then things get a bit more interesting.
One approach you can follow is to wrap the commands that need this path entry in a shim that adds it. Consider changing:
commands=
py test ...
to:
commands=
sh -c 'PATH=$PATH:$(chromedrive-path); exec "$#"' _ py test ...
Whenever I try to create a workspace:
~/catkin_ws$ catkin_make
It shows like this:
ImportError: "from catkin_pkg.package import parse_package" failed: No module named 'catkin_pkg'
Make sure that you have installed "catkin_pkg", it is up to date and on the PYTHONPATH.
CMake Error at /opt/ros/kinetic/share/catkin/cmake/safe_execute_process.cmake:11 (message):
execute_process(/home/usuario/miniconda3/bin/python
"/opt/ros/kinetic/share/catkin/cmake/parse_package_xml.py"
"/opt/ros/kinetic/share/catkin/cmake/../package.xml"
"/home/usuario/catkin_ws/build/catkin/catkin_generated/version/package.cmake")
returned error code 1
Call Stack (most recent call first):
/opt/ros/kinetic/share/catkin/cmake/catkin_package_xml.cmake:63 (safe_execute_process)
/opt/ros/kinetic/share/catkin/cmake/all.cmake:151 (_catkin_package_xml)
/opt/ros/kinetic/share/catkin/cmake/catkinConfig.cmake:20 (include)
CMakeLists.txt:52 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/usuario/catkin_ws/build/CMakeFiles/CMakeOutput.log".
See also "/home/usuario/catkin_ws/build/CMakeFiles/CMakeError.log".
Invoking "cmake" failed
It seems like there is a problem with catkin_pkg but I dont find the solution
I just installed ROS on Ubuntu 16.04, had the same issue, and fixed it. The location for catkin_pkg is likely not on your PYTHONPATH and needs to be added.
From the error output:
Make sure that you have installed "catkin_pkg", it is up to date and on the PYTHONPATH.
Try locating catkin_pkg and check your PYTHONPATH. catkin_pkg wasn't on my PYTHONPATH (likely due to other program installs), so I added it and ran catkin_make again, this time successfully.
~/catkin_ws$ locate catkin_pkg
/usr/lib/python2.7/dist-packages/catkin_pkg
~/catkin_ws$ echo $PYTHONPATH
/opt/ros/kinetic/lib/python2.7/dist-packages
To append the catkin_pkg dir to PYTHONPATH (for this session):
~/catkin_ws$ export PYTHONPATH=$PYTHONPATH:/usr/lib/python2.7/dist-packages
For permanency I appended the catkin_pkg dir to PYTHONPATH in my .bashrc (you might want to backup your .bashrc file first, e.g. cp -p ~/.bashrc ~/.bashrc-ros-catkin.bak).
To do this, edit your ~/.bashrc file (you might need to use sudo to edit this file) and add the following two lines to the end of the file:
# manually added for ROS catkin_make workspace setup
export PYTHONPATH=$PYTHONPATH:/usr/lib/python2.7/dist-packages
Save the file and run source to update your session:
~/catkin_ws$ source ~/.bashrc
Check your PYTHONPATH again:
~/catkin_ws$ echo $PYTHONPATH
/opt/ros/kinetic/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages
Obviously the location of your catkin_pkg files might be different to mine, so use that path instead when appending to $PYTHONPATH above.
Now try running catkin_make again. If you get the same error, paste the output of your catkin_pkg location and PYTHONPATH here.
Cheers,
sb
Are you using Anaconda environment?
This issue is quite common with Anaconda's Python installation.
Try: python --version
If you see Anaconda in the output, go to your bashrc file with vi ~/.bashrc and then comment the line where anaconda is added to path.
It would be something like,
export PATH="username/anaconda2/bin:$PATH"
After that source your bashrc with source ~/.bashrc, open a new terminal and navigate to your catkin workspace. Delete the old build folder and try the catkin_make command again.
Should solve your issue.
The Error Output:
ImportError: "from catkin_pkg.package import parse_package" failed: No module named 'catkin_pkg'
Make sure that you have installed "catkin_pkg", it is up to date and on the PYTHONPATH.
As mentioned above you need have "catkin_pkg" in PYTHONPATH. The easiest way if you ask me is:
$ pip install catkin_pkg
try this : pip install -U rosdep rosinstall_generator wstool rosinstall six vcstools
if pip shows any errror, switch to root and install pip and then try
Actually when you want to use Anaconda and ROS simultaneously then generally this error comes. So firstly go in .bashrc file and comment the path of anaconda.
Export PATH="/home/gaurav/anaconda3/bin:$PATH".
After commenting go in catkin_ws folder and delete the existing folder within the folder and make new src folder.
Then follow three steps:
1 - $ mkdir src
2 - $ catkin_init_workspace src
3 - $ catkin_make
It works for me.
This means you havent sourced ROS into your environment.
Add this line to the last line of your .bashrc file
source /opt/ros/kinetic/setup.bash
Save the .bashrc file, close the current terminal and start your process in a new terminal.
for me, it fixed by
sudo apt-get remove python3-catkin-tools
sudo apt-get install python-catkin-tools
My fabric file:
def deploy():
code_path = 'mysite/public_html/mysite'
with cd(code_path):
with prefix("workon mysite"):
run('git pull')
run('supervisorctl -c ~/supervisord.conf restart ' + env.host_string)
I get the following error:
Aborting.
[myserv] out: /bin/bash: workon: command not found
Obviously workon command works when I do this manually (without fabric). I suspect /usr/local/bin/virtualenvwrapper.sh is not being sourced (it normally gets run through .bash_profile).
What do I need to do to get workon command working?
Try modifying your prefix with:
with prefix(". /usr/local/bin/virtualenvwrapper.sh; workon mysite"):
you have to copy this virtualwrapper load code from .bashrc to .bash_profile file or if not exist create new .bash_profile file and copy there.
code to copy::
export WORKON_HOME=/home/virtual
source /usr/local/bin/virtualenvwrapper.sh
this error happen because .bashrc is only read by a shell that's both interactive and non-login. So in this case it is not interactive non-login shell, so it won't work. so we have to copy those code to .bash_profile file.
reference link
I use pyenv with plugin pyenv-virtualenvwrapper. I had no success with workon, instead I use this (fabric 2.5):
with c.prefix('source /home/mirek/.virtualenvs/%s/bin/activate' % PROJECT):
with c.prefix('cd /home/mirek/dj/%s/%s' % (PROJECT, PROJECT)):
c.run('python manage.py ....')