Using virtualenv in VMWare with shared Windows folder - python

I currently use a linux VM in VMWare running on a Windows machine. I have a shared Windows folder for my projects that I access in linux via /mnt/hgfs/
When I try to use virtualenv for my python projects I get an 'Operation not supported' error:
joe#myserver:/mnt/hgfs/winwww/envtest# virtualenv env
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 9, in <module>
load_entry_point('virtualenv==1.7', 'console_scripts', 'virtualenv')()
File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 928, in main
never_download=options.never_download)
File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 1029, in create_environment
site_packages=site_packages, clear=clear))
File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 1164, in install_python
copyfile(join(stdlib_dir, fn), join(lib_dir, fn))
File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 430, in copyfile
copyfileordir(src, dest)
File "/usr/local/lib/python2.6/dist-packages/virtualenv.py", line 405, in copyfileordir
shutil.copytree(src, dest, True)
File "/usr/lib/python2.6/shutil.py", line 173, in copytree
raise Error, errors
shutil.Error: [('/usr/lib/python2.6/config/libpython2.6.so', 'env/lib/python2.6/config/libpython2.6.so', '[Errno 95] Operation not supported')]
I'm assuming this is due to Windows not being able to handle symbolic links because I can create my virtualenvs in other directories.
Has anyone worked out a way to make virtualenv work in shared Windows folders? I edit my code on my Windows machine which is why I use shared folders.
Thanks.

The virtualenv does not need to be located next to your code, so even if you can't create it within your shared folder this shouldn't affect your ability to edit the code on windows and run it on your host platform. It sounds to me like a bad idea anyway to attempt to share platform-specific files with multiple platforms.
This is the usefulness of the .pth files and if you're using setuptools with a setup.py within your project you can just $VENV/python setup.py develop which will link your project into the virtualenv, wherever it may be located. You can then run $VENV/python and your package will be in the sys.path and available for import.

Related

How to Create Python virtual environment inside an USB Flash

I am running ubuntu 18.04.1 in virtual box, on windows 10. The Ubuntu is running 2.7 version python. The USB stick is mounted to the path /opt/ext_usb/yyyy. When I tried executing the command virtualenv my-env-name --no-site-packages , I am getting the following error.
Running virtualenv with interpreter /usr/bin/python2
New python executable in /opt/ext_usb/jpr_lamp/bin/python2
Also creating executable in /opt/ext_usb/jpr_lamp/bin/python
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/virtualenv.py", line 2375, in <module>
main()
File "/usr/lib/python3/dist-packages/virtualenv.py", line 724, in main
symlink=options.symlink)
File "/usr/lib/python3/dist-packages/virtualenv.py", line 946, in create_environment
site_packages=site_packages, clear=clear, symlink=symlink))
File "/usr/lib/python3/dist-packages/virtualenv.py", line 1417, in install_python
os.symlink(py_executable_base, full_pth)
OSError: [Errno 1] Operation not permitted
I would like to know why the permission is denied when creating python virtual environment inside an USB stick. Is it because the ubuntu is running in VM and USB is shared between the windows. Please Help !
Note:
I have tried creating symlink on USB stick using ln -s /usr/bin/python /sampe/path/inUsb and failed to create the symbolic link.
Is this the actual cause of the issue? If so, how to get rid of the issue. Thanks in advance !
Thanks for your comment #wholevinski
The USB stick that I have used has Fat32 file system and it won't support symbolic links. Able to create the symlinks after changing the file system from fat32 to NTFS. Now I am able to create python virtual environment in an USB flash.

Error using PyInstaller

I'm trying to use PyInstaller to create a standalone OSX app that runs a GUI I've made. When I enter the following in my terminal:
pyinstaller gui.py
Everything seems to work until I get the following error:
File "/Users/username/anaconda/bin/PyInstaller", line 11, in <module>
sys.exit(run())
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/__main__.py", line 90, in run
run_build(pyi_config, spec_file, **vars(args))
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/__main__.py", line 46, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/build_main.py", line 788, in main
build(specfile, kw.get('distpath'), kw.get('workpath'),
kw.get('clean_build'))
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/build_main.py", line 734, in build
exec(text, spec_namespace)
File "<string>", line 16, in <module>
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/build_main.py", line 212, in __init__
self.__postinit__()
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/datastruct.py", line 178, in __postinit__
self.assemble()
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/build_main.py", line 470, in assemble
module_hook.post_graph()
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/imphook.py", line 409, in post_graph
self._load_hook_module()
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/imphook.py", line 376, in
_load_hook_module
self.hook_module_name, self.hook_filename)
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/hooks/hook-PyQt4.py", line 33, in <module>
(qt_menu_nib_dir('PyQt4'), ''),
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/utils/hooks/qt.py", line 125, in qt_menu_nib_dir
""".format(namespace, path))
Exception:
Cannot find qt_menu.nib for PyQt4
Path checked:
/Users/felipe/miniconda/envs/_build/lib/QtGui.framework/Resources/qt_menu.nib
Which seems strange, since my name is not felipe!
I have a couple of questions:
1) How is it possible that there is a directory under the name felipe on my computer? (I used anaconda to install qt, I don't know whether that has something to do with it?)
2) Up until I get the error message, PyInstaller is looking in the correct folder. Why does it start looking in this vague (vague to me that is) directory I don't know of?
3) I'm quite a novice regarding directories and I can't find mister felipe anywhere on my computer. When I look in the Users folder I just see my own user and an empty "Shared" folder. (I don't know what the shared folder is used for and why it's there.)
4) Based on what I read on the internet, I copied qt_menu-nib to the folder where the script that's supposed to be turned into a standalone is located. What should I do in order to successfully create a standalone from here?
First of all, you face a known issue between PyInstaller and Anaconda: PyInstaller issue #2135. The conversation contains answers to your questions.
1) The path is hardcoded in the wrongly built Qt binary that is provided by Anaconda, see comment from mrady3.
2) PyInstaller loads Qt4-specific hook in order to find resources (qt_menu.nib) that are necessary for running target app. The hook code tries to obtain location of resource directory from the Qt binary itself. Qt binary returns wrong /hardcoded/ path, and after that process fails.
3) See point 1), it was a folder on maintainer's machine. Qt assumes that its installation path is pre-set before building; Anaconda repository hosts a binary that was compiled with another installation path in mind.
4) There could be several possible approaches:
Try installing developer version of PyInstaller from sources, it has some fixes for the above-mentioned issue. Then try building the app again:
git clone https://github.com/pyinstaller/pyinstaller.git
cd pyinstaller
/Users/username/anaconda/bin/python setup.py sdist
conda install dist/PyInstaller-3.3.dev0.tar.bz2
Install Qt4 using homebrew. Local compilation will take a long time:
brew install cartr/qt4/qt
find /usr/local/Cellar/qt -name qt_menu.nib
Edit Qt4 hook at /Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/hooks/hook-PyQt4.py and replace call to qt_menu_nib_dir('PyQt4') with the path from homebrew installation ('/usr/local/Cellar/qt/4.8.7_3/lib/QtGui.framework/Versions/4/Resources/qt_menu.nib').
Or alternatively, just put qt_menu.nib into expected location:
sudo mkdir -p /Users/felipe/miniconda/envs/_build/lib/QtGui.framework/Resources/
sudo ln -s /usr/local/Cellar/qt/4.8.7_3/lib/QtGui.framework/Versions/4/Resources/qt_menu.nib /Users/felipe/miniconda/envs/_build/lib/QtGui.framework/Resources/

"Can't extract file(s) to egg cache" error in GAE

I have Windows 7 and Python 2.7 with setuptools installed.
After i download pitz module (easy_install pitz), Google App Engine stop working:
bad runtime process port ['']
Traceback (most recent call last):
File "G:\Program Files (x86)\Google\google_appengine\_python_runtime.py", line 184, in <module>
_run_file(__file__, globals())
File "G:\Program Files (x86)\Google\google_appengine\_python_runtime.py", line 180, in _run_file
execfile(script_path, globals_)
File "G:\Program Files (x86)\Google\google_appengine\google\appengine\tools\devappserver2\python\runtime.py", line 28, in <module>
from google.appengine.ext.remote_api import remote_api_stub
File "G:\Program Files (x86)\Google\google_appengine\google\appengine\ext\remote_api\remote_api_stub.py", line 75, in <module>
import yaml
File "G:\Program Files (x86)\Google\google_appengine\lib\yaml-3.10\yaml\__init__.py", line 14, in <module>
from cyaml import *
File "G:\Program Files (x86)\Google\google_appengine\lib\yaml-3.10\yaml\cyaml.py", line 5, in <module>
from _yaml import CParser, CEmitter
File "C:\Python27\lib\site-packages\pyyaml-3.11-py2.7-win-amd64.egg\_yaml.py", line 7, in <module>
File "C:\Python27\lib\site-packages\pyyaml-3.11-py2.7-win-amd64.egg\_yaml.py", line 4, in __bootstrap__
File "C:\Python27\lib\site-packages\pkg_resources.py", line 950, in resource_filename
self, resource_name
File "C:\Python27\lib\site-packages\pkg_resources.py", line 1607, in get_resource_filename
self._extract_resource(manager, self._eager_to_zip(name))
File "C:\Python27\lib\site-packages\pkg_resources.py", line 1667, in _extract_resource
manager.extraction_error()
File "C:\Python27\lib\site-packages\pkg_resources.py", line 996, in extraction_error
raise err
pkg_resources.ExtractionError: Can't extract file(s) to egg cache
The following error occurred while trying to extract file(s) to the Python egg
cache:
[Error 5] : 'C:\\Users\\Kostr\\AppData\\Roaming\\Python-Eggs\\pyyaml-3.11-py2.7-win-amd64.egg-tmp\\_yaml.pyd'
The Python egg cache directory is currently set to:
C:\Users\Kostr\AppData\Roaming\Python-Eggs
Perhaps your account does not have write access to this directory? You can
change the cache directory by setting the PYTHON_EGG_CACHE environment
variable to point to an accessible directory.
How to solve this issue?
from: https://code.google.com/p/modwsgi/wiki/ApplicationIssues
To avoid this particular problem you can set the PYTHON_EGG_CACHE cache environment variable at the start of the WSGI application script file. The environment variable should be set to a directory which is owned and/or writable by the user that Apache runs as.
import os
os.environ['PYTHON_EGG_CACHE'] = '/usr/local/pylons/python-eggs'
Again, make sure this exists. For Windows users, maybe something like:
os.environ['PYTHON_EGG_CACHE'] = '/tmp'
Alternatively, if using mod_wsgi 2.0, one could also use the WSGIPythonEggs directive for applications running in embedded mode, or the python-eggs option to the WSGIDaemonProcess directive when using daemon mode.
Note that you should refrain from ever using directories or files which have been made writable to anyone as this could compromise security. Also be aware that if hosting multiple applications under the same web server, they will all run as the same user and so it will be possible for each to both see and modify each others files. If this is an issue, you should host the applications on different web servers running as different users or on different systems. Alternatively, any data required or updated by the application should be hosted in a database with separate accounts for each application.
Sounds like you don't have permissions to write to the directories. Uninstall pitz, and reinstall using the -Z tag to install it as the unzipped version. Then, you don't need the cache directory to extract each time. That should solve the directories / permissions issue.

Py2app with native Python 2.6

I have a python application primarily dependent on matplotlib, tkinter, numpy and scipy I have been distributing for multiple operating systems. I build these on top of the python.org version of python 2.6. For mac, I have had good success in the past with py2app and pyinstaller to build standalone versions of my application. Recently, however, I have included functions that require patsy, pandas and igraph and have had to move to the mac distributed version of python 2.6 in order to get igraph to work. All works fine in building a py2app version of my software on the Mac for my OS (10.6) but when I run on 10.8 I encountered the following error:
Traceback (most recent call last):
File "UI.pyc", line 603 createHeatMap
File "clustering.pyc", line 31, in <module>
File "mpl_toolkits/__init__.pyc", line 2, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 698, in <module>
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 701, in Environment
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 96, in get_supported_platform
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.py", line 222, in get_build_platform
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/util.py", line 98, in get_platform
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/sysconfig.py", line 537, in get_config_vars
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/sysconfig.py", line 405, in _init_posix
DistutilsPlatformError: invalid Python installation: unable to open /user/include/python2.6/pyconfig.h (No such file or directory)
This is fixed by saving the file pyconfig.h to the designated location on the destination machine (not present in 10.8 but present in 10.6), which allows my application to work fine. In my py2app pacakge directory, under "Contents/Resources" there is a sym-link to the directory "include" which points to: /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/pyconfig.h. If I include the pyconfig.h file as an addition resource in my py2app setup file, it also includes it in the package, but it still is not recognized.
Can anyone suggest a good work around for this that doesn't require me to use the python.org version of python (I've had horrible luck getting igraph to work with this).
Thanks...
This is a known issue in py2app, see https://bitbucket.org/ronaldoussoren/py2app/issue/36/py2app-fails-to-build-a-working-executable. The pyconfig.h file is only present on machines where the developer tools are installed, which is why I haven't noticed the problem myself.
The easiest workaround is probably to replace the pyconfig.h symlink by a copy of the file after creating the app bundle.

py2exe won't properly compile my application

I've never used py2exe before. I installed the package, created a setup.py, ran it and it seemed to work without any obvious errors. I went into the dist folder it created and tried to run the exe but I'm getting this error:
Traceback (most recent call last):
File "rl2.py", line 3, in <module>
File "libtcodpy.pyc", line 41, in <module>
File "ctypes\__init__.pyc", line 428, in __getitem__
File "ctypes\__init__.pyc", line 423, in __getattr__
File "ctypes\__init__.pyc", line 353, in __init__
WindowsError: [Error 126] The specified module could not be found
How can I solve this?
What exact commands did you use to get this output?
I recommend using PyInstaller.
You can build an EXE with PyInstaller using this command:
"python pyinstaller.py -y -w -F [PATH\TO\SCRIPT.py] -n [PROJECT_NAME]"
-y: answer yes to every question
-w: windowed (does not show commandline when running)
-F: Compile into one EXE instead of a directory with .dll files
-n: assign project name
Hope I helped
You probably need to manually specify ctypes in the packages section of your setup.py.
See here
I had same issue today. HEre is the solution will work 100%
The meaning of error is the imported dll file in your code is misssng in created dist folder. so you have to copy and paste dll file in dist folder, and it will work.
I used logimove.dll file and same issue. so i put logimove.dll file in dist file and it works. :)

Categories