I am very new to Python and Django and is currently busy learning myself through tutorials on www.djangoproject.com. I am using PyCharm and working on OS X El Capitan. I have imported a project from GitHub and created a virtual environment for the project interpreter based on Python 3.5.1. In the vm I installed django.
I then activated the vm.
Now.. I started by trying to execute simple commands in the terminal like python manage.py startapp deonapp and python manage.py runserver but each time I get an error which I pasted below.. What did I miss? I cannot seem to find the /log/ directory?
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/config.py", line 558, in configure
handler = self.configure_handler(handlers[name])
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/config.py", line 731, in configure_handler
result = factory(**kwargs)
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/__init__.py", line 1008, in __init__
StreamHandler.__init__(self, self._open())
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/__init__.py", line 1037, in _open
return open(self.baseFilename, self.mode, encoding=self.encoding)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/deon/Documents/PyCharmProjects/Developments/deonproject/log/debug.log'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/deon/Documents/PyCharmProjects/Developments/deonproject/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/Users/deon/Documents/PyCharmProjects/Developments/deonproject/venv/lib/python3.5/site-packages/django/core/management/__init__.py", line 341, in execute
django.setup()
File "/Users/deon/Documents/PyCharmProjects/Developments/deonproject/venv/lib/python3.5/site-packages/django/__init__.py", line 22, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/Users/deon/Documents/PyCharmProjects/Developments/deonproject/venv/lib/python3.5/site-packages/django/utils/log.py", line 75, in configure_logging
logging_config_func(logging_settings)
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/config.py", line 795, in dictConfig
dictConfigClass(config).configure()
File "/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/logging/config.py", line 566, in configure
'%r: %s' % (name, e))
ValueError: Unable to configure handler 'file': [Errno 2] No such file or directory: '/Users/deon/Documents/PyCharmProjects/Developments/deonproject/log/debug.log'
I managed to fix it. The log directory was not created because it was excluded in the .gitignore file. I completely forgot to look what was excluded :). I created the directory manually and now it passed the error.
Deon
you can add this in setting.py
LOG_PATH = os.path.join(BASE_DIR, 'log')
or
if not os.path.join(LOG_PATH):
os.mkdir(LOG_PATH)
Other answers can be true in most of cases, But In my case log directory was created, But log dir had permission issue to my user. simply using chown to my user (my case www-data) solved the problem.
(In my case):
sudo chown www-data:www-data /var/log/django/
use your username:user-group instead of www-data:www-data and your log dir instead of /var/log/django/.
Traceback says, that it's no "log" directory.
Create directory with name log in path /Users/deon/Documents/PyCharmProjects/Developments/deonproject/
Create empty file .gitkeep
After creating .gitkeep file, push it to GitHub
Related
When running either command:
sudo serverless package or sudo serverless deploy
I get the following traceback:
Error: ERROR: Exception: Traceback (most recent call last): File
“/var/lang/lib/python3.6/shutil.py”, line 550, in move os.rename(src,
real_dst) OSError: [Errno 18] Invalid cross-device link:
‘/tmp/pip-target-wqc5grcw/lib/python/setuptools’ ->
‘/var/task/setuptools’
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
“/var/lang/lib/python3.6/site-packages/pip/_internal/cli/base_command.py”,
line 228, in _main status = self.run(options, args) File
“/var/lang/lib/python3.6/site-packages/pip/_internal/cli/req_command.py”,
line 182, in wrapper return func(self, options, args) File
“/var/lang/lib/python3.6/site-packages/pip/_internal/commands/install.py”,
line 456, in run options.target_dir, target_temp_dir, options.upgrade
File
“/var/lang/lib/python3.6/site-packages/pip/_internal/commands/install.py”,
line 514, in _handle_target_dir target_item_dir File
“/var/lang/lib/python3.6/shutil.py”, line 561, in move symlinks=True)
File “/var/lang/lib/python3.6/shutil.py”, line 321, in copytree
os.makedirs(dst) File “/var/lang/lib/python3.6/os.py”, line 220, in
makedirs mkdir(name, mode) PermissionError: [Errno 13] Permission
denied: ‘/var/task/setuptools’
I’ve created several different projects and they work locally but they never progress beyond this invalid cross-link device Error when trying to deploy or package.
What are my options?
Edit: I tried nuking my virtualenv, uninstalling/re-installing serverless-python-requirements, deleting/re-pulling the lambci/lambda Docker image, no dice.
Then, I stumbled on this GH issue. As hinted in it, the experimental Docker feature Use gRPC FUSE for file sharing seems to be the cause. I've switched it off in the Docker Preferences for now and deploys are successful.
I just had a similar problem. See this issue for a possible solution.
In summary,
Remove all cached packages in /Library/Caches/serverless-python-requirements/
Remove existing docker image lambci/lambda build-python3.8
I have downloaded the appengine samples.
When I enter directory python-docs-samples/appengine/standard/django and install it on my appengine project, and then look at the project web page, I get this error:
Traceback (most recent call last):
File "/base/alloc/tmpfs/dynamic_runtimes/python27/b93f87cfaa0115e5_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/alloc/tmpfs/dynamic_runtimes/python27/b93f87cfaa0115e5_unzipped/python27_lib/versions/1/google/appengine/api/lib_config.py", line 358, in __getattr__
self._update_configs()
File "/base/alloc/tmpfs/dynamic_runtimes/python27/b93f87cfaa0115e5_unzipped/python27_lib/versions/1/google/appengine/api/lib_config.py", line 294, in _update_configs
self._registry.initialize()
File "/base/alloc/tmpfs/dynamic_runtimes/python27/b93f87cfaa0115e5_unzipped/python27_lib/versions/1/google/appengine/api/lib_config.py", line 165, in initialize
import_func(self._modname)
File "/base/alloc/tmpfs/dynamic_runtimes/python27/b93f87cfaa0115e5_unzipped/python27_dist/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/base/data/home/apps/s~forcediagnosticsclinic/20180707t052537.410964682053028174/appengine_config.py", line 18, in <module>
vendor.add('lib')
File "/base/alloc/tmpfs/dynamic_runtimes/python27/b93f87cfaa0115e5_unzipped/python27_lib/versions/1/google/appengine/ext/vendor/__init__.py", line 44, in add
'No such virtualenv or site directory' % path)
ValueError: virtualenv: cannot access lib: No such virtualenv or site directory
What is going on?
You app config refers to folder called lib and this folder is missing or you forgot to copy it properly. Try to get the same project working on your local computer.
Lenik is right. Specifically, it looks like you didn't do this step in the tutorial:
pip install -r requirements-vendor.txt -t lib/
https://cloud.google.com/python/django/appengine#run_the_app_on_your_local_computer
I am trying to set up a virtualenv for the first time and I can't figure out what the issue is. Here is the output in terminal...
Traceback (most recent call last):
File "/bin/virtualenv", line 3, in <module>
virtualenv.main()
File "/usr/lib/python2.7/site-packages/virtualenv.py", line 825, in main
symlink=options.symlink)
File "/usr/lib/python2.7/site-packages/virtualenv.py", line 960, in create_environment
site_packages=site_packages, clear=clear, symlink=symlink))
File "/usr/lib/python2.7/site-packages/virtualenv.py", line 1133, in install_python
mkdir(lib_dir)
File "/usr/lib/python2.7/site-packages/virtualenv.py", line 441, in mkdir
os.makedirs(path)
File "/usr/lib64/python2.7/os.py", line 150, in makedirs
makedirs(head, mode)
File "/usr/lib64/python2.7/os.py", line 150, in makedirs
makedirs(head, mode)
File "/usr/lib64/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: 'test_env'
I don't know why I would get a Permission denied error with just creating a virtualenv.
A virtualenv, on disk, is a directory with its own Python installation. The virtualenv utility needs to create this directory, and by default it puts it into your current directory (as opposed to some standardized location like ~/.venvs), which means that you need to be in the same directory as where you created the virtual environment every time you use it. The the Permission denied message comes from it not being able to create the directory in the first place.
Most likely you don’t have write permission to whatever directory you’re in. Your current directory (which you can find with pwd) should (usually) be somewhere in your home directory when trying to create a virtualenv.
Another possibility is that the directory already exists, but some of the necessary directory structure inside the virtualenv directory does not, and you don’t have write permission there. Usually, you want to use a name that does not correspond to an existing directory, and let the virtualenv tool create it for you.
Im learning Python.
Getting below exception while trying to clone a repos
Traceback (most recent call last):
File "C:\Users\Selvakumar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\git\cmd.py", line 622, in execute
**subprocess_kwargs
File "C:\Users\Selvakumar\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 969, in __init__
restore_signals, start_new_session)
File "C:\Users\Selvakumar\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 1249, in _execute_child
startupinfo)
PermissionError: [WinError 5] Access is denied
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "config_console.py", line 2185, in <module>
command_line = ConfigCommandLine()
File "config_console.py", line 87, in __init__
g.clone('git#github.com:Modria/Ecomm_GM.git')
File "C:\Users\Selvakumar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\git\cmd.py", line 463, in <lambda>
return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
File "C:\Users\Selvakumar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\git\cmd.py", line 905, in _call_process
return self.execute(make_call(), **_kwargs)
File "C:\Users\Selvakumar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\git\cmd.py", line 625, in execute
raise GitCommandNotFound(str(err))
git.exc.GitCommandNotFound: [WinError 5] Access is denied
GitPython is installed. ssh keys are available in C:\Users\Selvakumar.ssh and its working when I clone from git bash. But the same not working from python. Please note that ssh keys are generated with no password. Please help me to resolve it
The OP confirms it is a PATH/variable issue
Does your PATH references git binary?
Yes, that was the mistake I did. I missed to git.exe in GIT_PYTHON_GIT_EXECUTABLE path variable.
Given like this as C:\Program Files (x86)\Git\bin\git.exe and it works.
You can see that variable introduced here in GitPython 26
If set, it should contain the full path to the git executable, e.g. c:\Program Files (x86)\Git\bin\git.exe on windows or /usr/bin/git on linux.
The GitPyhton README states:
GitPython needs the git executable to be installed on the system and available in your PATH for most operations.
If it is not in your PATH, you can help GitPython find it by setting the GIT_PYTHON_GIT_EXECUTABLE=<path/to/git> environment variable.
seems like an authority error, be sure to run your script as an administrator
When I run a custom command in Django 1.8.3, I'm getting the following stack trace:
(env)MacBook-Air:backend user$ python manage.py questions
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/user/WeVote/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/Users/user/WeVote/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/user/WeVote/env/lib/python2.7/site-packages/django/core/management/base.py", line 393, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/user/WeVote/env/lib/python2.7/site-packages/django/core/management/base.py", line 444, in execute
output = self.handle(*args, **options)
File "/Users/user/WeVote/wevote/questions/management/commands/questions.py", line 14, in handle
OSError: [Errno 2] No such file or directory: '/Users/user/WeVote/backend/questions/question_files'
The error is valid, that filepath doesn't exist. I go to look at line 14 in questions.py, except that file doesn't exist. Boo.
As you can see, the file structure is different in referencing questions.py file. As some point, I'm sure that was the file structure. I also wrote this in Djano 1.7 and upgraded to 1.8. However, all the other custom commands (written both before and after the upgrade) are working just fine.
Just as a sanity check, I tried a
cd /Users/user/WeVote/wevote/questions/management/commands/
Nope. This is an issue because when I now edit my properly-located questions.py in the management/commands directory, the changes aren't reflected. It's like it's reading a cached version and location of this file.
Also tried deleting and rebuilding both virtualenv and database. No love on either. I'm sure it's something simple I'm overlooking, but I'm out of ideas.
Reference for anyone coming afterwards: The comments from yuvi and Paul Collingwood above succeeded in solving my issue. I ran
find . -name '*.pyc' -delete
and the next time I ran questions.py everything worked well. Thanks both for your comments.